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

0xb*_*00d 8 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.
Run Code Online (Sandbox Code Playgroud)

但是,指定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) {}
);
Run Code Online (Sandbox Code Playgroud)

oma*_*llo 19

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

我相信你正在寻找的是这个API,这让我想知道上面如何返回任何恢复,因为它期望a bounds而不是latLng,并且它也不支持language密钥.

但是,为了使用其他语言获得结果,您可以根据文档的此部分更改包含Google地图脚本的方式,例如

<script type="text/javascript" 
src="http://maps.googleapis.com/maps/api/js?sensor=false&language=ja"></script>
Run Code Online (Sandbox Code Playgroud)

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

http://maps.googleapis.com/maps/api/geocode/json?latlng=YOUR-LAT-LNG&language=en
Run Code Online (Sandbox Code Playgroud)