以下代码异步工作。我只设置了将城市,州转换为纬度和经度。然后会提醒该值。
如何编写一个实际返回这些值的函数?
var map;
var geocoder;
function initialize() {
geocoder = new GClientGeocoder();
}
// addAddressToMap() is called when the geocoder returns an
// answer. It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
//map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
} else {
place = response.Placemark[0];
latitude = place.Point.coordinates[0];
longitude = place.Point.coordinates[1];
alert("Latitude " + latitude + " Longitude" + longitude);
}
}
function showLocation(address) {
geocoder.getLocations(address, addAddressToMap);
}