I've been tasked with plotting various points onto a map. Due to financing and the nature of the project we can't use Google or any of that type of thing. So we have to do this the hard way using PHP or Javascript.

I'm supplied a map(Mercator) and the coordinates of the 4 corners of the map. With that information I need to convert the lat and lon into x / y coordinates that I can mark on the map.

function convert_map($lat, $lon)
   $width = 1281;
   $height = 1529;
// X and Y boundaries
$westLong = -75.196438;
$eastLong = -74.674072;
$northLat = 41.377581;
$southLat = 40.909232;

$lat = $lat;
$lon = $lon;

 $x = $width * (($westLong-$lon)/($westLong-$eastLong));
 $y = ($height * (($northLat-$lat)/($northLat-$southLat)));

	echo $x."<br />";
	echo $y;


It seems to mostly work for longitude but not latitude. I've been trying to read up on these various equations and such, but honestly, this stuff feels like it's over my head. I'm terrible with math.

Any help would be greatly appreciated. Thanks in advance.

7 Years
Discussion Span
Last Post by Ejl191

What I mean to say is that it seems to work for latitude and not longitude. Sorry, my brain is quite addled at the moment.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.