Reputation:
When I pass zipcodes from Holland, the API returns one location from Holland and one from Belgium. Here's my code:
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDbxcI_JLMuvKyeQGdho5bF0F0cj8eCGCU"></script>
<script>
origin = "3034, Netherlands";
destination = "9000, Netherlands";
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
}, callback);
function callback(response, status) {
console.log(response);
}
</script>
And this is the result:
Object {rows: Array[1], originAddresses: Array[1], destinationAddresses: Array[1]}
destinationAddresses: Array[1]
0: "9000 Gent, België"
length: 1
__proto__: Array[0]
originAddresses: Array[1]
0: "3034 Rotterdam, Nederland"
Can anyone tell me how to get results that are restricted to areas in the Netherlands? Thanks in advance.
Upvotes: 1
Views: 1437
Reputation: 29
you should append the country name or Code with postcode in origin and destination, then you will get the results from the same country.
Upvotes: 2
Reputation: 4960
At first refer to Distance Matrix Requests. You can declare location more specific, then i prefer to use google.maps.LatLng objects in Netherlands. When check the result, destination = "9000, Netherlands" doesn’t seem to be located in Netherlands.
This is sample about distance-matrix and refer to Google API distancematrix returning wrong json result in VBA (Same issue like your case. But this is related in VBA)
In addition to that If you want to limit zoom level in the map, refer to this Country specific zoom level in Google Maps API and Google Maps v3 - limit viewable area and zoom level.
Upvotes: 0