2010-05-28 89 views
0

我有以下代碼: 它基本上查看HTML列表並對每個項目進行地理編碼和標記。它可以正確地完成8次,但有時會出現我在控制檯中顯示的錯誤。谷歌地圖有時不會返回字符串的地理編碼值

我想不出任何東西。任何想法都非常感謝。

$(function() { 

var map = null; 
var geocoder = null; 

function initialize() { 
    if (GBrowserIsCompatible()) { 
     // Specifies that the element with the ID map is the container for the map 
     map = new GMap2(document.getElementById("map")); 
     // Sets an initial map positon (which mainly gets ignored after reading the adderesses list) 
     map.setCenter(new GLatLng(37.4419, -122.1419), 13); 
     // Instatiates the google Geocoder class 
     geocoder = new GClientGeocoder(); 
     map.addControl(new GSmallMapControl()); 
     // Sets map zooming controls on the map 
     map.enableScrollWheelZoom(); 
     // Allows the mouse wheel to control the map while on it 
    } 
} 


function showAddress(address, linkHTML) { 
    if (geocoder) { 
     geocoder.getLatLng(address, 

    function (point) { 
     if (!point) { 
      console.log('Geocoder did not return a location for ' + address); 
     } 
     else { 
      map.setCenter(point, 8); 
      var marker = new GMarker(point); 
      map.addOverlay(marker); 
      // Assigns the click event to each marker to open its balloon 
      GEvent.addListener(marker, "click", function() { 
       marker.openInfoWindowHtml(linkHTML); 
      }); 

     } 
    } 
); 
    } 
} // end of show address function 

initialize(); 

// This iterates through the text of each address and tells the map 
// to show its location on the map. An internal error is thrown if 
// the location is not found. 
$.each($('.addresses li a'), function() { 
    var addressAnchor = $(this); 
    showAddress(addressAnchor.text(), $(this).parent().html()); 
}); 
}); 

看起來這個HTML:

<ul class="addresses"> 
       <li><a href="#">Central London</a></li> 
       <li><a href="#">London WC1</a></li> 
       <li><a href="#">London Shoreditch</a></li> 
       <li><a href="#">London EC1</a></li> 
       <li><a href="#">London EC2</a></li> 
       <li><a href="#">London EC3</a></li> 
       <li><a href="#">London EC4</a></li> 
      </ul> 
+0

對所有基本評論感到抱歉。它的客戶誰需要知道每行是什麼 – XGreen 2010-05-28 16:11:09

+0

你是說,它間歇性地失敗了相同的地址,或者它只是在2/10一般失敗? – ScottE 2010-05-28 16:15:29

+0

它完全失敗。有時候地址是之前找到的,有時候是所有的。然後我刷新,它再次正常工作。 – XGreen 2010-05-28 16:17:57

回答

0

也許它的地理編碼器查詢限制,因爲你問的API來頻繁?
它只是一個猜測。我不止一次遇到這個問題。

+0

感謝您的答案虛擬化。這可能是你的建議。雖然我正在測試來自美國被批准國家的應用程序,但如果與此有關,那麼服務可能根本無法工作,而不是有時會失敗。我想這是我必須建議我的客戶獲得谷歌地圖商業許可的情況。 – XGreen 2010-06-02 10:04:31

相關問題