Hello Lars,
Yes, you can create route from gps to the destination.
For this goal please follow these steps:
ol
liYou need to store latitude and longitude into LSV with names: "originLatitude" and "originLongitude".
/liliReplace js asset from tutorial with following one: http://prntscr.com/39t4bu/direct
precode
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
}
function displayDirections(sourceAddress, destinationAddress, map) {
var coordinatesOrigin = localStorage.getItem("originLatitude") + "," + localStorage.getItem("originLongitude");
Code: Select all
console.log("origin coordinates = " + coordinatesOrigin);
var request = {
origin: coordinatesOrigin,
//origin: sourceAddress,
destination: destinationAddress,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
directionsDisplay.setMap(map);
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Directions query unsuccessful. Response status: " + status);
}
});
}/code/pre/li
Note: when you run "Get directories" functional you should see in your browser console something like this: "origin coordinates = 51.3030,0.0732" if coordinates are wrong - please check out first step.
That's all. All other tutorial things you should leave without changes.
Regards./ol