有没有任何方法(最好是使用REST API)获取与地理坐标对应的街道名称?我认为这个名字叫做地理编码,Google有提供这个API吗?我是PHP开发人员。
例如:
<?php
cor="38.115583,13.37579";
echo(geoname(cor)); // this prints: Foro Umberto I - 90133 Palermo
?>
因此,该函数的输出是街道名称、邮政编码和城市。感谢任何帮助和脚本示例!
有没有任何方法(最好是使用REST API)获取与地理坐标对应的街道名称?我认为这个名字叫做地理编码,Google有提供这个API吗?我是PHP开发人员。
例如:
<?php
cor="38.115583,13.37579";
echo(geoname(cor)); // this prints: Foro Umberto I - 90133 Palermo
?>
是的,只需在Google Maps API中使用“反向地理编码”功能即可:http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
这里是一些示例代码:
$lat="38.115583";
$long = "13.37579";
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
$address = json_decode($curlData);
print_r($address);
以下是我用于使用Google MAP API对街道地址进行反向地理编码查找的PHP函数。请注意,此示例从Google获取JSON输出,但我在PHP中进行了简单的解析。
/*
* Use Google Geocoding API to do a reverse address lookup from GPS coordinates
*/
function GetAddress( $lat, $lng )
{
// Construct the Google Geocode API call
//
$URL = "http://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&sensor=false";
// Extract the location lat and lng values
//
$data = file( $URL );
foreach ($data as $line_num => $line)
{
if ( false != strstr( $line, "\"formatted_address\"" ) )
{
$addr = substr( trim( $line ), 22, -2 );
break;
}
}
return $addr;
}
安德鲁 OpenGeoCode.Org 团队
顺便说一句> 谷歌对于商业用途使用他们的API有限制。基本上,你需要在谷歌地图上显示结果。
$url = 'http://where.yahooapis.com/geocode?location=55.948496,-3.198909&gflags=R&flags=J';
$response = json_decode(file_get_contents($url));
$location = $response->ResultSet->Results[0];
print_r($location);
SELECT * FROM geo.placefinder WHERE text="55.948496,-3.198909" AND gflags="R"
使用PHP调用该查询到YQL非常类似于之前的例子,并且应该打印出相同的信息。
$query = 'SELECT * FROM geo.placefinder WHERE text="55.948496,-3.198909" AND gflags="R"';
$url = 'http://query.yahooapis.com/v1/public/yql?q='.urlencode($query).'&format=json';
$response = json_decode(file_get_contents($url));
$location = $response->query->results->Result;
print_r($location);