davefootball123 Posted February 16, 2013 Share Posted February 16, 2013 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 More sharing options...
trq Posted February 16, 2013 Share Posted February 16, 2013 You might want to post some relevant code and a question. Link to comment https://forums.phpfreaks.com/topic/274555-map-x-y-to-lat-long/#findComment-1412750 Share on other sites More sharing options...
Barand Posted February 16, 2013 Share Posted February 16, 2013 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 More sharing options...
davefootball123 Posted February 16, 2013 Author Share Posted February 16, 2013 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.