简体   繁体   English

更改Google Maps API语言

[英]change Google maps API language

I'm using Azure platform to develop a website. 我正在使用Azure平台开发网站。 I'm using in Google maps API to get my location. 我在Google Maps API中使用它来获取我的位置。 The server side is written in C# I want that Google return the answer in English and not in other language. 服务器端是用C#编写的,我希望Google以英语而不是其他语言返回答案。 How can I do this? 我怎样才能做到这一点?

 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false" lang="en-us"></script> <script type="text/javascript"> var geocoder; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } //Get the latitude and the longitude; function successFunction(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; codeLatLng(lat, lng) } function errorFunction() { alert("Geocoder failed"); } function initialize() { geocoder = new google.maps.Geocoder(); } function codeLatLng(lat, lng) { var latlng = new google.maps.LatLng(lat, lng); geocoder.geocode({ 'latLng': latlng }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { console.log(results) if (results[1]) { //formatted address //alert(results[0].formatted_address) document.getElementById('<%= citylbl.ClientID %>').value = results[0].formatted_address; //find country name for (var i = 0; i < results[0].address_components.length; i++) { for (var b = 0; b < results[0].address_components[i].types.length; b++) { //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate if (results[0].address_components[i].types[b] == "administrative_area_level_1") { //this is the object you are looking for city = results[0].address_components[i]; break; } } } //city data //alert(city.short_name+" " + city.long_name); } else { alert("No results found"); } } else { alert("Geocoder failed due to: " + status); } }); } </script> </head> <body onload="initialize()"> <asp:HiddenField ID="citylbl" runat="server" /> </body> 

You need to add a language parameter in you API request. 您需要在API请求中添加语言参数。

For example: https://maps.googleapis.com/maps/api/js?language=ja will return information in Japanese. 例如: https://maps.googleapis.com/maps/api/js?language=ja : https://maps.googleapis.com/maps/api/js?language=ja将以日语返回信息。

You can visit this page about Google Maps Language Localization. 您可以访问有关Google Maps Language Localization的页面

Also, the list of supported languages . 另外, 支持的语言列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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