2012-04-12 120 views
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”。如果你将它们粘贴到谷歌地图中,​​它会显示“拉脱维亚里加”,所以坐标看起来是正确的。

现在,这是脚本的结果:

enter image description here

完全脱落,表明非洲附近某处点。

看来,getlocationcoords计算坐标错误。任何建议如何解决这个问题?谢谢!

节点:我不能使用谷歌地图或任何其他服务,我必须这样做。

回答

1

好的,所以问题真的很愚蠢,我把经度和纬度混合在一起,他们应该有其他的方式,现在一切正常。大声笑