可以用GClientGeocoder对象来获取。 function initialize() { if (GBrowserIsCompatible()) {
// Create and Center a Map var map = new GMap2(document.getElementById("map_canvas")); var geocoder = new GClientGeocoder(); map.setCenter(new GLatLng(37.4419, -122.1419), 13); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); GEvent.addListener(map,"click", function(overlay,latlng) { geocoder.getLocations(latlng, showAddress); });
if (GBrowserIsCompatible()) {
// Create and Center a Map
var map = new GMap2(document.getElementById("map_canvas"));
var geocoder = new GClientGeocoder();
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl()); GEvent.addListener(map,"click", function(overlay,latlng) {
geocoder.getLocations(latlng, showAddress);
});
}
}
function showAddress(response) {
if(response && response.Status.code == "200") {
alert("地址:" + response.Place[0].address);
alert("国家:" + response.Place[0].AddressDetails.Country.CountryName);
}
}