当我从荷兰传递zipcodes时,API返回荷兰的一个位置和比利时的一个位置。 这是我的代码:
<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>
这就是结果:
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"
有谁能告诉我如何获得仅限于荷兰地区的结果?提前谢谢。
答案 0 :(得分:0)
首先请参阅Distance Matrix Requests。您可以更具体地声明位置,然后我更喜欢在荷兰使用 google.maps.LatLng 对象。检查结果时,destination =“9000,Netherlands”似乎不在荷兰。
这是关于distance-matrix的示例,并引用Google API distancematrix在VBA中返回错误的json结果(与您的情况相同。但这与VBA相关)
除此之外如果您想限制地图中的缩放级别,请参阅Google Maps API和Google地图v3中的此国家/地区特定缩放级别 - 限制可见区域和zoom level。