2012-11-18 93 views
0

基本上,我試圖追蹤我的位置,每次我移動。谷歌地圖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 
    }); 

} 

回答

0
+0

它與Chrome和safari兼容嗎? –

+1

@ Tezro Solutions:是的,請參閱:https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition#Browser_compatibility –

0

這裏有很多細節。如果您不想從頭編寫自己的代碼,則可以使用GeolocationMarker,它是Google Maps API v3 Utility Library的一部分。它爲你處理很多小細節。由於它是開源的,你也可以修改它以適應你的需求。

+0

感謝您的回覆。我已經有了一個基礎,並且還研究如何實現上述代碼。我只是使用heads_change事件,它現在可以找到。 –