1
我试图制作一个简单的脚本,它将lon/lat作为参数,并将一个点放在单词映射图像上,很简单。在用户的世界地图上显示地理位置
<?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));
}
?>
请注意,我用下面的坐标 “56.946536,24.10485”。如果你将它们粘贴到谷歌地图中,它会显示“拉脱维亚里加”,所以坐标看起来是正确的。
现在,这是脚本的结果:
完全脱落,表明非洲附近某处点。
看来,getlocationcoords计算坐标错误。任何建议如何解决这个问题?谢谢!
节点:我不能使用谷歌地图或任何其他服务,我必须这样做。