简体   繁体   中英

Change the language in which Geocoder.geocode() returns results

As the API reference states:

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.

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) {}
);

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

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM