Showing geographic location on a world map of a user

我是研究僧i 提交于 2021-02-10 15:49:57

问题


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:

enter image description here

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!