基本上,我試圖追蹤我的位置,每次我移動。谷歌地圖API跟蹤設備
香港專業教育學院設法得到follwing代碼與'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
});
}
它與Chrome和safari兼容嗎? –
@ Tezro Solutions:是的,請參閱:https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition#Browser_compatibility –