Jump to content

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.