Created
November 23, 2012 10:35
-
-
Save frontconnect/4135005 to your computer and use it in GitHub Desktop.
cordova location tracker at background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("pause", App.pauseEvent, false); | |
pauseEvent: function(){ | |
navigator.geolocation.watchPosition( | |
function(pos){ | |
App.latlngs.push(new L.LatLng(pos.coords.latitude, pos.coords.longitude)); | |
}, | |
function(err){ | |
alert('Error:' + err); | |
}, | |
{ frequency:1000, maximumAge: 0 } | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
navigator.geolocation.watchPosition( | |
function(pos){ | |
// App.map.setView([pos.coords.latitude, pos.coords.longitude], App.curZoom); | |
//build up the latlng array | |
App.latlngs.push(new L.LatLng(pos.coords.latitude, pos.coords.longitude)); | |
//remove the route before | |
if(App.route != null) | |
App.map.removeLayer(App.route); | |
//add the new latlng array on the map | |
App.route = L.polyline(App.latlngs,{color: 'red'}).addTo(App.map); | |
}, | |
function(err){ | |
alert('Error:' + err); | |
}, | |
{ frequency:1000, maximumAge: 0 } | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment