Jump to content

Map X Y to Lat long


davefootball123

Recommended Posts

Hi again, hopefully the last thread I make for a while...

I have an image seen here. http://www.sowx.ca/warnings.html

I have an onclick script that gets X and Y coordinates via the $_GET method. I need to convert those coordinates to $lat $lon.

 

The corner latitude longitudes are seen here. If anyone can help me covert map click x y to latitude longitude that would be awesome.

 

Thanks for all the help, Dave

Top Left:
Latitude: 45.62809 
Longitude: -84.73936



Bottom Left:
Latitude: 41.50190
Longitude: -84.37040





Bottom Right: 
Latitude: 41.63353
Longitude: -77.13030



Top Right:
Latitude: 45.78681
Longitude: -76.98868

Link to comment
https://forums.phpfreaks.com/topic/274555-map-x-y-to-lat-long/
Share on other sites

This won't be exact because of the non-rectangular nature of the corner coordinates but it may be near enough for you to find the nearest location to the click

 

$width = 800;
$height = 610;
/***************************************************
Top Left:				   Top Right:
Latitude: 45.62809		  Latitude: 45.78681
Longitude: -84.73936	    Longitude: -76.98868

Bottom Left:			    Bottom Right:
Latitude: 41.50190		  Latitude: 41.63353
Longitude: -84.37040	    Longitude: -77.13030
****************************************************/
$minlat = 41.50190;
$maxlat = 45.78681;
$minlong = -76.98868;
$maxlong = -84.73936;

$x = $_GET['map_x'];
$y = $_GET['map_y'];

$lat = $maxlat - ($maxlat - $minlat) * $y / $height;
$lon = $maxlong - ($maxlong - $minlong) * $x / $width;

echo "$lat, $lon";

Link to comment
https://forums.phpfreaks.com/topic/274555-map-x-y-to-lat-long/#findComment-1412783
Share on other sites

This won't be exact because of the non-rectangular nature of the corner coordinates but it may be near enough for you to find the nearest location to the click

 

$width = 800;
$height = 610;
/***************************************************
Top Left:				 Top Right:
Latitude: 45.62809		 Latitude: 45.78681
Longitude: -84.73936	 Longitude: -76.98868

Bottom Left:			 Bottom Right:
Latitude: 41.50190		 Latitude: 41.63353
Longitude: -84.37040	 Longitude: -77.13030
****************************************************/
$minlat = 41.50190;
$maxlat = 45.78681;
$minlong = -76.98868;
$maxlong = -84.73936;

$x = $_GET['map_x'];
$y = $_GET['map_y'];

$lat = $maxlat - ($maxlat - $minlat) * $y / $height;
$lon = $maxlong - ($maxlong - $minlong) * $x / $width;

echo "$lat, $lon";

Thanks for the help Barand...I'm gonna have to create a more accurate map with rectangular corner lat/lon lol.

Link to comment
https://forums.phpfreaks.com/topic/274555-map-x-y-to-lat-long/#findComment-1412788
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.