更改Geocoder.geocode()返回结果的语言

时间:2011-11-30 15:46:08

标签: javascript google-maps google-maps-api-3

由于API引用声明:

The Geocoding API defines a geocoding request using the following URL parameters:

 - language (optional) — The language in which to return results. See the supported list of domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the geocoder will attempt to use the native language of the domain from which the request is sent wherever possible.

但是,指定language参数似乎没有效果(使用Firefox 8,IE 9和Chrome 15进行测试)。

new google.maps.Geocoder().geocode({
    'latLng'  : new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
    'language': 'en'}, 
    function(results, status) {}
);

1 个答案:

答案 0 :(得分:18)

您引用的API链接与您在代码示例中使用的API链接不同。

我相信你所寻找的是this API,这让我想知道上面如何返回任何恢复,因为它期待bounds而不是latLng,而且它也是不支持language密钥。

但是,为了使用其他语言获得结果,您可以根据this section of the docs更改包含Google地图脚本的方式

<script type="text/javascript" 
src="http://maps.googleapis.com/maps/api/js?sensor=false&language=ja"></script>

另一方面,如果您真的使用Geocoding API (Web service),那么您的网址请求需要看起来像这样(如果您想要xml,请将json更改为xml,并将en更改为您想要的任何语言)

http://maps.googleapis.com/maps/api/geocode/json?latlng=YOUR-LAT-LNG&language=en
相关问题