更改Geocoder.geocode()返回结果的语言 [英] Change the language in which Geocoder.geocode() returns results

查看:471
本文介绍了更改Geocoder.geocode()返回结果的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如 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 参数doesn' (Firefox 8,IE 9和Chrome 15测试)。

However, specifying the language parameter doesn't seem to have effect (tested with Firefox 8, IE 9 and Chrome 15).

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


推荐答案

您引用的API链接不一样就像你在代码示例中使用的那样。

The API link you are refering to is not that same as what you are using in your code example.

我认为你要找的是这个API ,这让我想知道上述是如何返回任何restuls的,因为它期望 bounds 而不是 latLng ,并且它不支持语言键。

I beleive what you are looking for is this API, which makes me wonder how the above returns any restuls, since it is expecting a bounds and not latLng, and also it does not support the language key.

然而,为了在另一种语言中获得结果,您可以根据文档的这一部分像这样

However in order to get the results in another language you can change the way you include your google maps script according to this section of the docs like so

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

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

On the other hand if you are really working with the Geocoding API (Web service), then your url requests need to look something like this (changing the json to xml if you want xml out, and changing en to whatever language you want)

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

这篇关于更改Geocoder.geocode()返回结果的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆