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计算坐标错误。有什么建议可以解决这个问题吗?谢谢!

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

4

1 回答 1

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

于 2012-04-14T20:20:20.387 回答