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 Geocoding service . 为此,您需要使用链接文章中描述的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'];
}
1 回答
你需要在Google Maps API的GClientGeocoder对象上使用getLocations方法
EDIT :好的你正在做这个东西服务器端 . 这意味着您需要使用HTTP Geocoding service . 为此,您需要使用链接文章中描述的URL格式发出HTTP请求 . 您可以解析HTTP响应并提取地址:
N.B. Google Maps terms of service明确声明禁止将结果放在Google Map上进行地理编码数据 .