次のコードは非同期で動作します。都市、州を緯度と経度に変換するように設定しただけです。その後、その値が警告されます。
これらの値を実際に返す関数を作成するにはどうすればよいですか?
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);
}