2009-01-03 68 views
0

我注意到我的地理編碼器在下面顯示的代碼中是不一致的,因爲在調用「getLatLng」方法之前,我顯示了10個有效位置,但是在這行代碼之後,實際顯示的點數在每次搜索時都不相同(相同的搜索標準 - fyi)隨機在5和10之間..很奇怪Google Maps API - 使用getLatLng方法的GClientGeocoder不一致?

任何人都有類似的問題?如果是的話,你是如何解決它們的?

geocoder = new GClientGeocoder(); 
geocoder.getLatLng(address, function(point) { 
if (point) { 
     var icon = new GIcon(); 
     var marker = new GMarker(point, { icon: icon }); 
     GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); 
     map.addOverlay(marker); 

回答

0

我實際上發現它不是造成這種不一致的「驗證地址」代碼,而是 - 地圖API不需要大量地理編碼器調用,因此我添加了一個簡單的225ms超時每個請求之間以及這並獲得成功

function preGeoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus) { 
     addPreCount(); 

     //don't change this timeout as it was the lowest timeout that still worked w/ the api 
     var timeout = parseInt(precount) * 225; 

     window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout); 
    } 
1

我在ASP.NET應用程序中看到了這個。我的問題是,我在顯示地址之前驗證了地址,並且

  1. 我的一些地址有誤。

  2. 他們的地址驗證系統只能處理客戶端在每次調用時的一定數量的請求。

在地理編碼(IMO)之前清理地址會更好。

嘗試驗證您的地址,並嘗試限制您發送的地址數量以僅測試並查看每個請求是否連續。

希望有所幫助。

+0

所以,如果我刪除的代碼驗證行,如果(點){...這是否確認你在說什麼或? – 2009-01-03 15:37:45

1

試試看這個樣子,這樣我得到了34分與一個運行:

function addAddress(address,runde) { 
    geocoder.getLatLng(
    address, 
    function(point) { 
     if (!point) { 
     //alert(address + " not found"); 
     if (runde<5) { // rekursiv, try adress 5 times to get 
      window.setTimeout(function() {addAddress(address,runde+1);}, 1000); // wait 1 second bevor next try 
      } 
     } else { 
     var marker_add = new GMarker(point); 
     //alert(marker.getLatLng()); 
     leftClick(0, marker_add.getLatLng()); // function, add marker to map 
     } 
    } 
); 
} 
1

我不知道該addPreCount()做什麼。但我認爲很明顯,超時應該像索引乘以實際的超時常量。

因此,假設定義的超時常數225超時傳遞向地理編碼器的包裝將是:

var timeout = [index_of_each_xaddr] * 225; 
window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout);