我正在使用google api获取带有邮政编码的地址及其工作
但我想限制它只选择国家,我怎么样?
这是我的代码,使用zipcode获取地址我怎么能在这个api中传递国家
var obj = {};
obj.address = value;
$.ajax({
type: "GET",
url: "https://maps.googleapis.com/maps/api/geocode/json",
// contentType: "application/json; charset=utf-8",
dataType: 'json',
data: obj,
async: false,
success: function (res) {
console.log(res);
getValueFromZipcode = res;
assignData(getValueFromZipcode);
},
error: function (err) {
callLoader(false);
swal({
title: "Something Wents Wrong", text: "", type: "error",
showCancelButton: false, closeOnConfirm: true, confirmButtonText: "OK",
}, function (isConfirm) {
window.location = "signin";
});
// console.log(err);
}
});
答案 0 :(得分:0)
var country = 'IN';
var postal_code = 560068;
$.ajax({
type: "GET",
url: "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&components=country:"+country+"|postal_code:"+postal_code+"",
// contentType: "application/json; charset=utf-8",
dataType: 'json',
data: obj,
async: false,
success: function (res) {
console.log(res);
},
error: function (err) {
callLoader(false);
swal({
title: "Something Wents Wrong", text: "", type: "error",
showCancelButton: false, closeOnConfirm: true, confirmButtonText: "OK",
}, function (isConfirm) {
window.location = "signin";
});
// console.log(err);
}
});