我有一个地理编码功能,它将输入的地址值拉入表单并将它们放入地理编码调用中。响应应该写入纬度和范围。进入数据库的经度值 - 不幸的是,我的lat&多头回归南极洲。想法?
//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);
}
答案 0 :(得分:3)
可能还有其他错误,但要启动它会看起来像KML returns point coordinates in (long, lat) order,而你却期待相反的错误。