我正在使用Google方向API繪製2個地點A和B之間的路徑路徑。我可以做到這一點。現在,我需要檢查給定的地點C落在A和B的路徑路徑中。方向api:檢查某個地點是否落入兩個地點之間的路徑路徑
下面是我從代碼生成的路徑路徑的快照。
以下是相應的代碼:
function initialize() {
var input = document.getElementById('searchTextFieldSource');
var input1 = document.getElementById('searchTextFieldDestination');
var autocomplete = new google.maps.places.Autocomplete(input);
var autocomplete1 = new google.maps.places.Autocomplete(input1);
google.maps.event.addListener(autocomplete1, 'place_changed', function() {
var place = autocomplete.getPlace();
document.getElementById('city1').value = place.name;
var place1Lat = place.geometry.location.lat();
var place1Lng = place.geometry.location.lng();
document.getElementById('cityLat1').value = place1Lat;
document.getElementById('cityLng1').value = place1Lng;
var obj = new Object();
obj.city =place.name;
obj.latitude = place.geometry.location.lat();
obj.longitude = place.geometry.location.lng();
locations.push(obj);
var place2 = autocomplete1.getPlace();
document.getElementById('city2').value = place2.name;
var place2Lat = place2.geometry.location.lat();
var place2Lng = place2.geometry.location.lng();
document.getElementById('cityLat2').value = place2Lat;
document.getElementById('cityLng2').value = place2Lng;
var obj = new Object();
obj.city = place2.name;
obj.latitude = place2.geometry.location.lat();
obj.longitude = place2.geometry.location.lng();
locations.push(obj);
directionsDisplay = new google.maps.DirectionsRenderer();
var startPlace = new google.maps.LatLng(place1Lat, place1Lng);
var mapOptions = {
zoom:7,
center: startPlace
}
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
directionsDisplay.setMap(map);
//refreshMap(locations);
var start = $("#city1").val();
var end = $("#city2").val();
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
});
}
我怎麼能走呢?
我看不到 「的地方C」 在你的代碼。一種選擇是使用RouteBoxer爲您的路線確定一個合理的界限。如果中間點包含在這些邊界內,那可能足夠好了,否則您可以執行進一步的測試(例如距離路線折線的距離。請參見[此類似的問題](http://stackoverflow.com/questions/20476917/find -a-place-lies-between-source-and-destination-google-maps-and-places-api)(它也沒有答案) – geocodezip
可能的重複[如何獲取地點(例如加油站)沿着谷歌地圖API中的出發地和目的地之間的路線](http://stackoverflow.com/questions/17283826/how-to-to-get-places-eg-gas-stations-along-route-between-origin-and- destinati) – geocodezip
[加油站沿(在〜0.25英里範圍內)](http://www.geocodezip.com/v3_SO_RouteBoxerPlaces_configurable.html?dist=0.25&to=Electronics%20City&from=BTM%20Layout&type=gas_station&name=&submit=) – geocodezip