Basically, i’m trying to track my position every time I move.
Ive managed to get the follwing code working with the 'click' listener event, just to test it, I’m just not sure what and how i’d use the correct event listener on the fly:
function mapRoute(showPosition3, position){
var routeCoordinates = [new google.maps.LatLng(53.388639, -1.4785248000000002)];
var polyOptions = {
path: routeCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
}
flightPath = new google.maps.Polyline(polyOptions);
flightPath.setMap(map);
google.maps.event.addListener(map, 'click', addLatLng);
}
/**
* Handles click events on a map, and adds a new point to the Polyline.
* @param {MouseEvent} mouseEvent
*/
function addLatLng(event) {
var path = flightPath.getPath();
// Because path is an MVCArray, we can simply append a new coordinate
// and it will automatically appear
path.push(event.latLng);
// Add a new marker at the new plotted point on the polyline.
var marker = new google.maps.Marker({
position: event.latLng,
title: '#' + path.getLength(),
map: map
});
}
I would suggest to use geolocation.watchPosition()