【发布时间】:2019-10-30 17:25:03
【问题描述】:
我的项目有一个州/加拿大省的下拉列表,我选择那些 基于邮政编码的州通过 google.geocoder 找出城市或州
虽然我在加拿大使用 geocoder.geocode 以 french 响应,而我需要 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