2011-11-30 76 views
6

作爲API參考狀態的語言:更改其中Geocoder.geocode()返回結果

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

回答

15

您引用的API鏈接與您在代碼示例中使用的鏈接不同。

我beleive你在找什麼是this API,這讓我不知道上面怎麼回報任何restuls,因爲它是期待一個bounds,而不是latLng,而且它不支持language關鍵。

但是爲了得到在另一種語言的結果,您可以更改包括這樣你的谷歌根據this section of the docs像這樣

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

在另一方面,如果你真的與Geocoding API (Web service)工作映射腳本,那麼你的URL請求需要看起來像這樣(改變JSON爲XML,如果你想XML列,並改變連接到任何你想要的語言)

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

這是不完全正確的:一個'GeocoderRequest'對象可以包含一個類型的「位置」 'LatLng'。但你是對的,我不能用這種方式來指定語言。 – 0xbadf00d

+0

@SaschaHoll是的,我忽略了'location',但它仍然不應該被稱爲'latlng',因爲你已經包含在你的問題中。 – omarello

+0

包括語言參數很好,雖然我沒有在其他設備或瀏覽器上測試過,但是提前感謝你。 – hina10531