I want to do the recording of the route with Google Maps in the background. If the app is closed or the screen is locked, the markers should still be set and recording should continue. What options are there to implement this? I just do not know how to do that anymore. Please help me.
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 15
});
var infoWindow = new google.maps.InfoWindow({map: map});
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function(err) {
// error
});
var watchId = {},
watchOptions = {
timeout : 1 * 60 * 1000,
enableHighAccuracy: false
};
function delay(){
setTimeout(function(){ }, 3000);
}
var watchId = $cordovaGeolocation.watchPosition(watchOptions);
var lastUpdateTime = new Date();
var minFrequency = 4000;
watchId.then(
null,
function(err) {
console.log('Error: ' + err);
},
function(position) {
var now = new Date();
if(lastUpdateTime && now.getTime() - lastUpdateTime.getTime() < minFrequency){
console.log("Ignoring position update");
return;
}
lastUpdateTime = now;
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
//Setzt die Marker um später die Route nachzustellen und dei Distanz zu berechnen.
new google.maps.Marker({
position: new google.maps.LatLng(pos['lat'],pos['lng']),
map: map,
title: 'Hello World!'
}).setMap(map);
console.log("Latitude: " + pos['lat'] + " and Longitude: " + pos['lng']);
});