问题
I'm trying to make a simple script that takes lon/lat as an argument and places an dot on a word map image, simple.
<?php
if(empty($long))$long = 56.946536;
if(empty($lat)) $lat = 24.10485;
$im = imagecreatefromjpeg("earth_310.jpg");
$red = imagecolorallocate ($im, 255,0,0);
$scale_x = imagesx($im);
$scale_y = imagesy($im);
$pt = getlocationcoords($lat, $long, $scale_x, $scale_y);
imagefilledrectangle($im,$pt["x"]-2,$pt["y"]-2,$pt["x"]+2,$pt["y"]+2,$red);
header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);
function getlocationcoords($lat, $lon, $width, $height)
{
$x = (($lon + 180) * ($width / 360));
$y = ((($lat * -1) + 90) * ($height / 180));
return array("x"=>round($x),"y"=>round($y));
}
?>
Notice that I'm using The following coordinates "56.946536, 24.10485". If you paste them in google maps, it would show "Riga, Latvia", so coordinates appear to be correct.
Now this is the result of the script:
Completely off, shows the dot somewhere near Africa.
It appears that getlocationcoords calculates the coordinates wrong. Any suggestions how to fix this please? Thank you!
Node: I cannot use Google maps or any other services, I must do it this way.
回答1:
ok, so the problem was really stupid, I mixed up longitude with latitude, they should have went other way around, now everything works. lol
来源:https://stackoverflow.com/questions/10121879/showing-geographic-location-on-a-world-map-of-a-user