2010-03-19 74 views

回答

0

爲此,使用Geonames webservice apis相當容易,特別是the postalCodeSearch方法。雖然緩存結果通常是值得的,但除非您每秒發出多個查詢,否則在我的經驗中效果很好。 (即:不經常更改。)

1

是的,這是很容易與谷歌地圖地理編碼getLocations()做到這一點。

<html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Geocoding example</title> 
    <script src="http://maps.google.com/maps?file=api&v=2" type="text/javascript"></script> 
    <script type="text/javascript"> 
    var geocoder; 
    var map; 
    var address = "10001"; //NEW YORK zip 
    function load() 
    { 
     map = new GMap2(document.getElementById("map")); 
     geocoder = new GClientGeocoder(); 
     geocoder.getLocations(address, addToMap); 
    } 
    function addToMap(response) 
    { 
     place = response.Placemark[0]; 
     point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]); 
     map.setCenter(point, 13); 
     marker = new GMarker(point); 
     map.addOverlay(marker); 
     marker.openInfoWindowHtml(place.address); 
    } 
    </script> 
    </head> 
    <body onload="load()" onunload="GUnload()"> 
    <div id="map" style="width: 500px; height: 500px"></div> 
    </body> 
</html> 

您可以試試Google代碼playground
玩得開心!