<?php
// This map would show Germany:
// This also controls the aspect ratio of the projection
$width = 1000;
$height = 1500;
// Formula for mercator projection y coordinate:
function mercY
($lat) { return log(tan($lat/2 + M_PI
/4)); }
// Some constants to relate chosen area to screen coordinates
$ymin = mercY($south);
$ymax = mercY($north);
$xFactor = $width/($east - $west);
$yFactor = $height/($ymax - $ymin);
function mapProject($lat, $lon) { // both in radians, use deg2rad if neccessary
global $xFactor, $yFactor, $west, $ymax;
$x = $lon;
$y = mercY($lat);
$x = ($x - $west)*$xFactor;
$y = ($ymax - $y)*$yFactor; // y points south
}
$pts = array( // Source: Wikipedia "Berlin", 52, 31, 13, 24,
"Hamburg", 53, 33, 10, 00,
"Muenchen", 48, 08, 11, 35,
"Koelln", 50, 56, 06, 57,
);
for ($i = 0; $i != count($pts); $i += 5) { $name = $pts[$i];
$lat = deg2rad($pts[$i + 1] + $pts[$i + 2]/60); $lon = deg2rad($pts[$i + 3] + $pts[$i + 4]/60); $res = mapProject($lat, $lon);
$x = $res[0];
$y = $res[1];
print("$name: $x, $y\n");
}
?>
PD9waHAKCi8vIFRoaXMgbWFwIHdvdWxkIHNob3cgR2VybWFueToKJHNvdXRoID0gZGVnMnJhZCg0Ny4yKTsKJG5vcnRoID0gZGVnMnJhZCg1NS4yKTsKJHdlc3QgPSBkZWcycmFkKDUuOCk7CiRlYXN0ID0gZGVnMnJhZCgxNS4yKTsKCi8vIFRoaXMgYWxzbyBjb250cm9scyB0aGUgYXNwZWN0IHJhdGlvIG9mIHRoZSBwcm9qZWN0aW9uCiR3aWR0aCA9IDEwMDA7CiRoZWlnaHQgPSAxNTAwOwoKLy8gRm9ybXVsYSBmb3IgbWVyY2F0b3IgcHJvamVjdGlvbiB5IGNvb3JkaW5hdGU6CmZ1bmN0aW9uIG1lcmNZKCRsYXQpIHsgcmV0dXJuIGxvZyh0YW4oJGxhdC8yICsgTV9QSS80KSk7IH0KCi8vIFNvbWUgY29uc3RhbnRzIHRvIHJlbGF0ZSBjaG9zZW4gYXJlY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