Javascript 谷歌地图api跟踪设备
基本上,每次我移动时,我都在努力跟踪自己的位置 我成功地获得了以下代码来处理Javascript 谷歌地图api跟踪设备,javascript,google-maps-api-3,Javascript,Google Maps Api 3,基本上,每次我移动时,我都在努力跟踪自己的位置 我成功地获得了以下代码来处理'click'侦听器事件,只是为了测试它,我不确定我将如何动态使用正确的事件侦听器: function mapRoute(showPosition3, position){ var routeCoordinates = [new google.maps.LatLng(53.388639, -1.4785248000000002)]; var polyOptions = { path: routeC
'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
});
}
我建议使用这涉及到很多细节。如果您不想从头开始编写自己的代码,可以使用,它是的一部分。它为您处理许多小细节。由于它是开源的,您也可以修改它以满足您的需要。谢谢您的回复。我已经有了一个工作的基础,并且我还研究了如何实现上面的代码。我只是简单地使用了Head_change事件,它现在就可以工作。它与chrome、safari和ie兼容吗?@Tezro Solutions:是的,请参阅: