基本上,我每次移动时都会尝试跟踪我的位置。
我已经设法让以下代码与'click'
侦听器事件一起工作,只是为了测试它,我只是不确定我会动态使用正确的事件侦听器以及如何使用:
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
});
}