2
我有問題。 我想計算當前位置和計算出的路線之間的距離。我正在使用Google Maps API v3來計算路線。我試圖使用google.maps.geometry.poly.isLocationOnEdge,但它沒有奏效。獲取當前位置和計算出的路線之間的距離
這裏是我的代碼:
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK){
var poly = new google.maps.Polyline({
paths:new Array(result.routes[0].overview_path)
});
var currentPosition = new google.maps.LatLng(51.574470000000005, 4.32713);
if(google.maps.geometry.poly.isLocationOnEdge(currentPosition, poly)){
console.log("On route");
}else{
console.log("Not on route");
}
var directionsDisplay = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: color,
strokeWeight: 3
}
});
directionsDisplay.setMap(map);
directionsDisplay.setDirections(result);
}
});
我不知道這是爲了得到我想要的結果的好方法。
有人可以幫助我嗎?
由於這是不可能的!我要試一下。讓你保持最新! – 2015-03-26 19:02:09
它的工作原理!問題在於概述路徑。 //檢查位置是在航線 \t \t \t \t如果(!google.maps.geometry.poly.isLocationOnEdge( \t \t \t \t \t新google.maps.LatLng(received_data [ '緯度'],received_data [ '經度']), \t \t \t \t \t新google.maps.Polyline({ \t \t \t \t \t \t路徑:result.routes [0] .overview_path}), \t \t \t \t \t \t .00001 * reach)){} – 2015-05-12 11:46:43