繁体   English   中英

从地理编码获取错误的经度和纬度

[英]getting wrong latitude & longitude from geocoding

我有一个地址解析功能,可以将输入的地址值拉入表单并将其放入地址解析调用中。 该响应应该将纬度和经度值写入数据库-不幸的是,我的经纬度都回到了南极洲。 有什么想法吗?

//Set up our variables
$longitude = "";
$latitude = "";


//Three parts to the querystring: q is address, output is the format (
$key=$er_mapapi; 
$address=str_replace(' ', '%20', $_REQUEST['street_num'] . ' ' . $_REQUEST['address2'] . ', ' . $loccity . ', ' . $ststate . ', ' . $_REQUEST['postcode'] . ', ' . $cncount); 
$url = "http://maps.google.com/maps/geo?q=".$address."&output=json&key=".$key;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);
curl_close($ch);

$geo_json = json_decode($data, true);

print_r($geo_json);

if ($geo_json['Status']['code'] == '200') {


$latitude = $geo_json['Placemark'][0]['Point']['coordinates'][0];
$longitude = $geo_json['Placemark'][0]['Point']['coordinates'][1];


echo "Latutide: $latitude \n";
echo "Longitude: $longitude \n";

if ($latitude != '') $row->declat = $latitude; if ($longitude != '') $row->declong = $longitude; 


} else {
echo "Error in geocoding! Http error ".substr($data,0,3);
}

可能还存在其他错误,但开始时看起来像KML以(long,lat)顺序返回点坐标 ,并且您期望相反。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM