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

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.

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.

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.

Hasn’t unfolding map this function?

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)

1 Like

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

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?

float Xcord;
float Ycord;

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