Sto utilizzando l'API di Google Direction per tracciare il percorso del percorso tra 2 posti A e B. Sono in grado di farlo. Ora, ho il requisito di verificare se un posto C cade nel percorso percorso di A e B.Direction api: controlla se un posto cade nel percorso del percorso tra 2 posti
Ecco l'istantanea del percorso percorso che ho generato dal mio codice.
Ecco il codice corrispondente:
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);
}
});
});
}
Come posso fare?
non vedo "posto C" nel codice. Un'opzione è usare RouteBoxer per determinare un limite ragionevole per il tuo percorso. Se il punto intermedio è contenuto da quei limiti, ciò potrebbe essere abbastanza buono, altrimenti puoi eseguire ulteriori test (come la distanza dalla polilinea del percorso. Vedi [questa domanda simile] (http://stackoverflow.com/questions/20476917/find -a-place-lies-between-source-and-destination-google-maps-and-places-api) (che non ha una risposta) – geocodezip
possibile duplicato di [Come ottenere posti (ad es. stazioni di servizio) lungo il percorso tra origine e destinazione nell'API di Google Maps] (http://stackoverflow.com/questions/17283826/how-to-to-get-places-eg-gas-stations-along-route-between-origin-and- destinati) – geocodezip
[Stazioni di rifornimento lungo (entro ~ 0,25 miglia di) percorso] (http://www.geocodezip.com/v3_SO_RouteBoxerPlaces_configurable.html?dist=0.25&to=Electronics%20City&from=BTM%20Layout&type=gas_station&name=&submit=) – geocodezip