2011-07-14 47 views
3

是否有一個谷歌地圖api,將允許您傳遞一個位置名稱,它會返回座標指向谷歌地圖上的位置?好的google.maps地理位置api?

+0

我甚至都不知道Google Maps Data API不再可用:http://code.google.com/intl/nl/apis/maps/documentation/mapsdata/他們提供了另一種選擇。 – Harmen

回答

0

是的,需要使用反向地理位置。你可以發送一個地址或位置字符串,它會給你一個可能的緯度/經度座標數組。這些是GeocoderResults,通常第一個是你想要的。就像,如果你想在美國,你可以做

geocoder.geocode({'address': 'USA' }, function(results, status) { 
    response($.map(results, function(item) { 
    var latlng = new google.maps.LatLng(item.geometry.location.lat(), item.geometry.location.lng()); 
    //Do some action with the provided latlng 
    })); 
}); 
2

這裏是The Google Geocoding API

下面是一個例子請求:

http://maps.googleapis.com/maps/api/geocode/xml?address=Berlin&sensor=false

您可以篩選結果:爲geometry/location/latlng

<GeocodeResponse> 
    <status>OK</status> 
    <result> 
    <type>locality</type> 
    <type>political</type> 
    <formatted_address>Berlin, Deutschland</formatted_address> 
    […] 
    <geometry> 
     <location> 
     <lat>52.5234051</lat> 
     <lng>13.4113999</lng> 
     </location> 
     <location_type>APPROXIMATE</location_type> 
     <viewport>[…]</viewport> 
     <bounds>[…]</bounds> 
    </geometry> 
    </result> 
</GeocodeResponse> 
0

Mappy a同樣提供相同的免費服務。看看mappy.com並搜索其餘的api。