我试图设置一个邮政编码,以获得拉特和长坐标,并在其上放置一个标记。到现在为止,一切都很好。谷歌地图API在特定国家搜索邮编
问题来了,当我给一个邮政编码输入,它最终在世界的另一个地方的某处做标记。
例:I型2975-435,我得到: https://maps.googleapis.com/maps/api/geocode/json?address=2975-435&key=YOURKEY
"formatted_address" : "Balbey Mahallesi, 435. Sk., 07040 Muratpaşa/Antalya, Turquia",
我想使这个邮政编码葡萄牙只进行搜索。
https://maps.googleapis.com/maps/api/geocode/json?address=2975-435+PT 这样我得到:
"formatted_address" : "2975 Q.ta do Conde, Portugal",
正是我想要的。
问题是,我如何在JS代码中做到这一点? 这里是我必须在之前的代码现在
function codeAddress() {
var lat = '';
var lng = '';
var address = document.getElementById("cp").value;
geocoder.geocode({ 'address': address},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
//Just to keep it stored
positionArray.push(new google.maps.LatLng(lat,lng));
//Make the marker
new google.maps.Marker({
position:new google.maps.LatLng(lat,lng),
map:map
});
}else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
谢谢