更改Google Maps API语言

廖尔科

我正在使用Azure平台开发网站。我在Google Maps API中使用它来获取我的位置。服务器端是用C#编写的,我希望Google以英语而不是其他语言返回答案。我怎样才能做到这一点?

<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>

您需要在API请求中添加语言参数。

例如:https://maps.googleapis.com/maps/api/js?language=ja将以日语返回信息。

您可以访问有关Google Maps Language Localization的页面

另外,支持的语言列表

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

动态更改iOS版Google Maps API的响应语言

来自分类Dev

更改地图边界Google Maps API

来自分类Dev

Google Maps API和跨语言环境的城市搜索

来自分类Dev

Google Maps API更改了我的字体系列

来自分类Dev

Google Maps Api将多边形更改为圆形

来自分类Dev

Javascript Google Maps api addDomListener更改此上下文

来自分类Dev

如何分别存储和更改坐标-Google Maps API

来自分类Dev

Google Maps API-最接近的点-更改排序顺序

来自分类Dev

JavaScript Google Maps API-更改标记的标题

来自分类Dev

最终如何在Google Maps API中更改标记位置?

来自分类Dev

Google Maps API RefererNotAllowedError

来自分类Dev

Google Maps API DeletedApiProjectMapError

来自分类Dev

Google Maps Api许可

来自分类Dev

Google Maps Api

来自分类Dev

Google Maps REST API

来自分类Dev

Google Maps API请求

来自分类Dev

Google Maps Directions API

来自分类Dev

Google Maps API参数

来自分类Dev

如何以编程方式更改Android Google Maps V2中的语言

来自分类Dev

为Google Maps iframe设置语言

来自分类Dev

Google Maps Javascript API与Google Maps Embed API

来自分类Dev

缺少Google Maps RouteBoxer API

来自分类Dev

异步加载Google Maps API

来自分类Dev

动态加载Google Maps API

来自分类Dev

Google Maps API的JavaScript框架

来自分类Dev

Google Maps API搜索限制

来自分类Dev

Google Maps Api机场搜索

来自分类Dev

Google Maps Geocoding的API密钥

来自分类Dev

Google Maps API密钥错误