# How do you find the latitude and longitude of a image map when hovering or clicking the mouse?

**URL:** <https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063>\
**Category:** Coding Questions\
**Created:** [April 23, 2020, 12:22pm UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063 "2020-04-23T12:22:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stage1](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Stage1](https://discourse.processing.org/u/Stage1)\
**Post date:** [April 23, 2020, 12:22pm UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/1 "2020-04-23T12:22:06Z")

</div>

Hi, i would like to know if there is a way to find the coordinates of an image when clicked on a specific area on the image or when hovered over with a mouse.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 23, 2020, 1:00pm UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/2 "2020-04-23T13:00:17Z")

</div>

> [@Stage1](#):
>
> if there is a way to find the coordinates of an image when clicked on a specific area on the image or when hovered over with a mouse.

This question is not specific enough (or the title doesn’t really fit the text?)

Did you look at unfolding map?

When you click in an image, see mouseX and mouseY

I don’t know about unfolding maps. But should be documented.

---

<div class="post-metadata">

**Author:** ![Stage1](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Stage1](https://discourse.processing.org/u/Stage1)\
**Post date:** [April 24, 2020, 1:00am UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/3 "2020-04-24T01:00:02Z")

</div>

Sorry, what i ment was when clicking or hovering an area on a 2d image map how will i find the coordinate of it when i move my mouse to that location.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 24, 2020, 7:38am UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/4 "2020-04-24T07:38:56Z")

</div>

Hasn’t unfolding map this function?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 24, 2020, 8:05am UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/5 "2020-04-24T08:05:21Z")

</div>

If your 2D image is `w*h` pixels and the top left hand corner is at display location [x, y] then the mouse position over the second image `[xi, yi]` is given by

`xi = mouseX - x`  
`yi = mouseY - y`

and if you have a boolean variable `isOver` then

`isOver = (xi >= 0 && xi < w && yi >= 0 && y < h)`

is true when the mouse is over the image.

Assuming that latitude goes from -\pi/2 (north) to \pi/2 (south) and the latitude goes from 0 (west) to 2\pi (east) and the mouse is over the image then

`lat = map(yi, 0, h, -PI/2, PI/2)`  
`long = map(xi, 0, w, 0, 2*PI)`

---

<div class="post-metadata">

**Author:** ![stf](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@stf](https://discourse.processing.org/u/stf)\
**Post date:** [April 25, 2020, 1:55am UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/6 "2020-04-25T01:55:19Z")

</div>

I’m assuming you wish to know the lat/lon for any given mouseX/mouseY position, over some image of some map? If so, you must have a geo-referenced map image, one for which the cardinal extents are known. There’s a few different ways to arrive at these values - geotiffs, using a gis to reference, deriving from gps data - but you must have them in order to map the mouse xy to lat/lon. Also, independent of geo-referencing, yet dependent on the map scale, you may have to account for cartographic projections. Its possible to have a geo-referenced map projected incorrectly, which would render any lat/lon values invalid.

/tf

---

<div class="post-metadata">

**Author:** ![Stage1](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Stage1](https://discourse.processing.org/u/Stage1)\
**Post date:** [April 28, 2020, 10:03pm UTC](https://discourse.processing.org/t/how-do-you-find-the-latitude-and-longitude-of-a-image-map-when-hovering-or-clicking-the-mouse/20063/7 "2020-04-28T22:03:40Z")

</div>

I’ve managed to create the code to find the coordinates on the image, but when i insert this onto the latitude and longitude field of the coordinates on the CSV file they do not show on the map.

What am i doing wrong?

```auto
float Xcord;
float Ycord;

 void mouseClicked() {
 if (mouseButton == LEFT) {
    Xcord = pmouseX;
    Ycord = pmouseY;
  println(Xcord + "," + Ycord);
}
}

```
