[Google Maps Geocoder以法语显示返回加拿大的答复,而我需要英语答复

问题描述 投票:-1回答:1

我的项目在加拿大的州/省中具有下拉列表,我选择了这些基于邮政编码的州,通过google.geocoder找出城市或州

虽然我正在加拿大使用法语中的geocoder.geocode响应,而我需要english中的响应。

 var geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'address': "G1B0A3, Canada" }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results.length >= 1) {
                    for (var ii = 0; ii < results[0].address_components.length; ii++) {
                        var types = results[0].address_components[ii].types.join(",");
                        if (types.includes("locality")) {
                            $("#City").val(results[0].address_components[ii].long_name);
                            city = results[0].address_components[ii].long_name;
                        }
                        if (types == "administrative_area_level_1,political") {
                            $(".StateClass option").each(function () {
                                if ($(this).text().toUpperCase() == results[0].address_components[ii].long_name.toUpperCase()) {
                                    if (typeof (state) != "undefined") {
                                        state = $(this).val();
                                        $(".StateClass").val($(this).val());
                                    }
                                    else {
                                        $(this).attr('selected', true);
                                        state = $(this).val();
                                        $(".StateClass").val(state);
                                    }
                                }
                            });
               }
           }
        }
    }
}
javascript google-maps google-geocoder
1个回答
0
投票
Geocoding API docs中清楚地阐明了此行为:

language-返回结果所用的语言。
© www.soinside.com 2019 - 2024. All rights reserved.