2011-07-14 30 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。