Mur*_*esh 15 php google-maps google-code reverse-geocoding
我需要一个函数来使用谷歌地图api反向地理编码和php从坐标(lat,long)获取最近的地址或城市...请提供一些示例代码
Red*_*ing 34
您需要在Google Maps API中的GClientGeocoder对象上使用getLocations方法
var point = new GLatLng (43,-75);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) {
// access the address from the placemarks object
alert (result.address);
});
Run Code Online (Sandbox Code Playgroud)
编辑:好的.你正在做这个东西服务器端.这意味着您需要使用HTTP地理编码服务.为此,您需要使用链接文章中描述的URL格式发出HTTP请求.您可以解析HTTP响应并提取地址:
// set your API key here
$api_key = "";
// format this string with the appropriate latitude longitude
$url = 'http://maps.google.com/maps/geo?q=40.714224,-73.961452&output=json&sensor=true_or_false&key=' . $api_key;
// make the HTTP request
$data = @file_get_contents($url);
// parse the json response
$jsondata = json_decode($data,true);
// if we get a placemark array and the status was good, get the addres
if(is_array($jsondata )&& $jsondata ['Status']['code']==200)
{
$addr = $jsondata ['Placemark'][0]['address'];
}
Run Code Online (Sandbox Code Playgroud)
注意:Google地图服务条款明确规定,禁止在不将结果放入Google地图的情况下对地理数据进行地理编码.
| 归档时间: |
|
| 查看次数: |
41466 次 |
| 最近记录: |