【问题标题】:Showing geographic location on a world map of a user在用户的世界地图上显示地理位置
【发布时间】:2012-04-24 16:46:31
【问题描述】:

我正在尝试制作一个简单的脚本,它以 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 计算了错误的坐标。有什么建议可以解决这个问题吗?谢谢!

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

【问题讨论】:

    标签: php gd geo


    【解决方案1】:

    好的,所以这个问题真的很愚蠢,我把经度和纬度混淆了,他们应该反过来,现在一切正常。哈哈

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-26
      • 1970-01-01
      相关资源
      最近更新 更多