Ich versuche, eine Postleitzahl zu setzen, um Lat und Long Koordinaten zu erhalten und eine Markierung darauf zu setzen. Bis jetzt ist alles in Ordnung.Google Maps API Suche Postleitzahlen in einem bestimmten Land
Das Problem kommt, wenn ich eine PLZ-Eingabe gebe und es irgendwo in einem anderen Teil der Welt einen Marker macht.
Ex: Ich tippe 2975-435 und ich bekomme: https://maps.googleapis.com/maps/api/geocode/json?address=2975-435&key=YOURKEY
"formatted_address" : "Balbey Mahallesi, 435. Sk., 07040 Muratpaşa/Antalya, Turquia",
Und ich will diese Postleitzahl machen nur in Portugal gesucht werden.
https://maps.googleapis.com/maps/api/geocode/json?address=2975-435+PT Auf diese Weise erhalte ich:
"formatted_address" : "2975 Q.ta do Conde, Portugal",
Genau das, was ich wollte.
Das Problem ist, wie mache ich das in JS-Code? Hier ist der Code, den ich bis jetzt
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);
}
});
}
Danke