Skip to content

Instantly share code, notes, and snippets.

@frontconnect
Created November 23, 2012 10:35
Show Gist options
  • Save frontconnect/4135005 to your computer and use it in GitHub Desktop.
Save frontconnect/4135005 to your computer and use it in GitHub Desktop.
cordova location tracker at background
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 }
);
}
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