Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a two points:

1) start point
2) destination point

To draw the path between the two points im doing so with the function shown below called calculateAndDisplayRoute():




What i want to do is track the user live location marker to be shown on the drawn path and also how can i test user live location when im using localhost.

Any help is appreciated.

What I have tried:

function calculateAndDisplayRoute(directionsService, directionsDisplay) {

var dest;
if ($("#pac-input").val() != "") {
dest = $("#pac-input").val();
} else { dest = GlobalstartPoint }

directionsService.route({
origin: dest,
destination: document.getElementById('endPoint').value,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, function (response, status) {
console.log(response)
console.log(status)
if (status === 'OK') {
directionsDisplay.setDirections(response);
//var route = response.routes[0];
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
Posted
Updated 8-Nov-18 4:24am
v2
Comments
Dave Kreskowiak 8-Nov-18 11:34am    
I'm confused. Geolocation cannot be used to track a person as they move. It refers to a process where IP addresses are mapped to physical locations and it's nowhere near accurate.

Are you talking about using GPS instead?
SherryT6$ 8-Nov-18 13:31pm    
Hello Dave, yes it is possible i just read about navigator.geolocation.watchPosition
It tracks the position of the device on the move.
RedDk 8-Nov-18 12:51pm    
Try developers.google.com ... for sample code ... as the above appears to be specific or altered generality.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900