I've got a map (Mercator), and the coordinates of the 4 corners of the map. I need to come up with something so I can convert given coordinates to corresponding points on the map. I can't use google or anything of the sort, which is why I'm needing to do this in the first place.
The languages I can use are either going to be PHP or Javascript. I've tried so开发者_C百科me things that I've found in other posts such as this one: Mercator longitude and latitude calculations to x and y on a cropped map (of the UK), but I haven't had any luck with them.
If anyone can offer some assistance I would be really grateful. I'm terrible with math and looking at some of these equations this is starting to feel out of my league, but I've got to get it done.
Again, thank in advance.
function convert_coords($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;
}
This is what I've been trying to get to work. It's a variation of something I pulled off here, I think, but it doesn't get me the results I need. I've really run into a brick wall with this one badly. And there is no way on earth I'm going to figure out the math here on my own, I've been trying and it's way out of my league.
it sounds like you're working in JavaScript, in which case, the proj4js open source library is worth a look.
Also, assuming your bitmap is orthogonal with the coordinate system, then you could take the Mercator forumla (look in Wikipedia or any half decent map objection book) apply a simple linear transform to get the transform you need. Then solve for the four corners. for the linear transform, you will find some of the variables simply duplicate parameters in the Mercator projection (ie. The scaling factors)
精彩评论