以下代碼異步工作。我只設置了將城市,州轉化爲經緯度。然後該值被警告。Google的GeoCode將城市狀態轉換爲經度經度
我該如何編寫一個實際返回這些值的函數?
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);
}
這正是我第一次嘗試,但它是在表單提交,並沒有及時設置值。我可能需要用ajax狡猾 – pws5068 2010-07-14 13:37:00
@ pws5068:隨意發表另外一個問題,顯示錶單提交前進行地理編碼時遇到的問題...我們來看看:) – 2010-07-14 13:51:29