您需要使用获取位置 http://code.google.com/apis/maps/documentation/reference.html#GClientGeocoder.getLocations方法上的G客户端地理编码器 http://code.google.com/apis/maps/documentation/reference.html#GClientGeocoder对象在谷歌地图 API http://code.google.com/apis/maps/documentation/reference.html
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);
});
EDIT: 好的。你正在服务器端做这些事情。这意味着您需要使用HTTP 地理编码服务 http://code.google.com/apis/maps/documentation/geocoding/index.html#ReverseGeocoding。为此,您需要使用链接文章中描述的 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'];
}
N.B. The Google 地图服务条款 https://developers.google.com/maps/documentation/geocoding/policies#map明确规定禁止对数据进行地理编码而不将结果放在 Google 地图上。
您可以在 Google 地图上显示 Geocoding API 结果,也可以在没有地图的情况下显示
地图。如果您想在地图上显示 Geocoding API 结果,那么这些
结果必须显示在 Google 地图上。禁止使用
对非 Google 地图的地图上的 API 数据进行地理编码。