[英]Reverse geocoding with Google Maps API
我發現此代碼可用於反向地理編碼:
var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { alert (lat[1]+' '+long[1]+' '+result.address); });
但是它彈出警報,說result.address是'undefined'。 有什么想法,可能是什么問題?
編輯:可以了,謝謝。
您可以包括“ lat”和“ long”的定義嗎? 另外,“ long”是保留關鍵字,因此很可能是拼寫錯誤/錯誤。
同樣,返回的結果(至少以gmaps v2 json格式)具有更復雜的結構,並且“ result.address”將沒有任何結果。 當我對其進行測試時,我需要使用以下方式訪問其中一個地址:
result.Placemark[0].address
請參閱http://code.google.com/apis/maps/documentation/geocoding/index.html#Geocoding響應
由此,我只能說result
沒有傳遞給函數或它不是對象。
您需要查看回調函數接收哪些參數。 文檔說明如下:
此響應將包含狀態代碼,如果成功,還將包含一個或多個地標對象。
如果您使用的是Firebug,則可以通過以下方式查看傳遞給回調的內容:
var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) {
window.console.log(arguments);
// Here you will see what arguments are passed and
// decide what to do about them
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.