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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.