2011-10-27 143 views

回答

1

我有一個類似的問題,在這裏發佈的代碼:

how to use the google maps api with greasemonkey to read a table of addresses and trace the route?

看一看,檢查它是否可以幫助你。

下面的代碼使用美國郵政編碼來返回狀態,但我相信你可以修改它以滿足你的需求。

var geocoder = new google.maps.Geocoder(); 

function getState(zipcode) { 
    geocoder.geocode({ 'address': zipcode}, function (result, status) { 
     var state = "N/A"; 
     for (var component in result[0]['address_components']) { 
      for (var i in result[0]['address_components'][component]['types']) { 
       if (result[0]['address_components'][component]['types'][i] == "administrative_area_level_1") { 
        state = result[0]['address_components'][component]['short_name']; 
        // do stuff with the state here! 
        document.getElementById('state').innerHTML = state; 
        return; 
       } 
      } 
     } 
    }); 
} 

--- EDITED [28/10/2011] ---

確定。非常簡單的例子,不需要代碼。
click here

所有你需要做的就是改變郵編SW1A它說的地方center=SW1A,UK
不能得到任何簡單的:)

+0

感謝您的迴應......但說實話我還是有點失落。 – Adam

+0

好的。編輯我的答案。看一看。 – RASG

相關問題