it is possible to use the geolocation in the background sending the current latitude and longitude with a "setInterval" in IONIC1? - ionic-framework

Basically I want to make a web request in second plane (for example when the cell phone is blocked, or not being used) every 4 hours to a web service that receives the current latitude and longitude. is this possible?
I have researched a lot, and apparently there is no way to do this, unless a plugin is used that detects movement and activates geolocation. for example:
https://github.com/transistorsoft/cordova-background-geolocation
my client wants the idea that every 4 hours a web service is consumed that receives the current latitude and longitude and verify the stores that are nearby in the current place

try this inside your function
let config = {
desiredAccuracy: 0,
stationaryRadius: 20,
distanceFilter: 10,
debug: true,
interval: 2000 // Set the interval to your desired time.
};
this.backgroundGeolocation.configure(config).subscribe((location) => {
console.log('BackgroundGeolocation: ' + location.latitude + ',' + location.longitude);
// Run update inside of Angular's zone
this.zone.run(() => {
this.lat = location.latitude;
this.lng = location.longitude;
});
}, (err) => {
console.log(err);
});
// Turn ON the background-geolocation system.
this.backgroundGeolocation.start();

Related

Using Ionic Capcitor geolocation plugin, Iphone its taking around 45sec to 1.5 mins to fetch current location

I am using capcitor geolocation plugin to find current location coordinates(latitude and longitude).
const coordinates = await Geolocation.getCurrentPosition({enableHighAccuracy:true});
const center = {lat: coordinates.coords.latitude, lng: coordinates.coords.longitude};
But in Iphone its taking around 45sec to 1.5 mins to fetch current location.
I have alao used below code. But this is sometime fast sometime slow.
const id = await Geolocation.watchPosition({}, (coordinates, err) => {
Geolocation.clearWatch({id});
if(err) {
console.log(err)
}
console.log('getCenter ios',coordinates);
const center = {lat: coordinates.coords.latitude, lng: coordinates.coords.longitude};
});
Is there any other implementation or free/paid plugin available, which can fetch current location coordinates faster on iphone.

What is the difference between Exif GPS DestLatitude vs Latitude

In the EXIF metadata GPS schema there are two places to store GPS data:
#1-4 Latitude, LatitudeRef, Longitude and LongitudeRef
#19-23 DestLatitude, DestLatitudeRef, DestLongitude and DestLongitudeRef
In theory the first is where the photo was taken, so an iPhone will populate this data. The second are the coordinates of the object in the photo. So if you are on Westminster Bridge and taking a photo of the London Eye, you'd have two slightly different values.
Does anyone know if there's accepted usage of these properties?
Specifically, should Latitude only be set if you have GPS data from either the camera or an external logger, so this could be considered optional? But the DestLatitude would be always set on any, well organized photo collection?
The second is referenced as "destination point".
You can see those in W3 exif, prefixed by gps, which suggests it makes only sense when you record a position relative to a fixed destination point.
You can see that field used in tomchentw/react-google-maps for example:
withScriptjs, withGoogleMap,
lifecycle({
componentDidMount() {
this.setState({
onDirectionChange: () => {
const DirectionsService = new google.maps.DirectionsService();
DirectionsService.route({
origin: new google.maps.LatLng(this.props.latitude, this.props.longitude),
destination: new google.maps.LatLng(this.props.destLatitude, this.props.destLongitude),
travelMode: google.maps.TravelMode.DRIVING,
}, (result, status) => {
if (status === google.maps.DirectionsStatus.OK) {
this.setState({
directions: result
});
} else {
console.error(`error fetching directions ${result}`);
}
});
}
});
const DirectionsService = new google.maps.DirectionsService();
In that case, this is to call Google Map in order to launch an itinerary computation.

Ionic 3: BackgroundLocation updates are too rare

I'm currently facing a problem that is not so nice. I already created an issue but no response. I need every location change to update the camera center position. But this doesn't happen. The refresh is not definable with time. It's just very rare for my needs. Android and iOS is the same. The log is called every minute or something like that.
Also I tried the console log outside the ngZone but it's the same.
This is what my configuration code looks like:
let config = {
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 0,
debug: true,
interval: 2000,
pauseLocationUpdates: false,
activityType: "AutomotiveNavigation"
};
this.backgroundGeolocation.configure(config).subscribe((location) => {
// Run update inside of Angular's zone
this.zone.run(() => {
if(this.map) {
this.map.getMyLocation().then( (userLocation: MyLocation) => {
console.log("INSIDE ZONE Google Maps Location \n LAT: " + userLocation.latLng.lat + "\nLNG: " + userLocation.latLng.lng);
this.userLocation = userLocation.latLng;
this.speed = userLocation.speed;
this.bearing = userLocation.bearing;
this.altitude = location.altitude;
this.cameraFollow();
this.notify(this.nearestReports[0]);
}).catch( error => {
alert("Background - NO GPS FOUND: " + error);
});
}
});
});
// Turn ON the background-geolocation system.
this.backgroundGeolocation.start();
Consider using another Ionic Native plugin called Geolocation.
There is a very handy watchPosition() function in there that looks like what you are looking for. Here's an example:
let options = {
enableHighAccuracy: true,
timeout: Infinity, // don't return response until new ping is available from OS, to save battery
maximumAge: 0
};
const subscription = this.geolocation.watchPosition(options)
.filter((p) => p.coords !== undefined) //Filter Out Errors
.subscribe(position => {
console.log(position.coords.longitude + ' ' + position.coords.latitude);
});
Don't forget to stop the subscription when not needed in order to save battery:
subscription.unsubscribe();

When I start the App with GPS off , and later GPS is activated, Location is not detected

I am having problems with GPS detection over Google Maps in Ionic App. When I start the App with GPS off and later I change from Settings device to GPS on, clicking by Find Me button - centerOnMe() function - the GPS is not working. The function responses always
`Error: GPS Timeout! ERROR = 3`
At the beginning I thought that was a cache problem but I have found out that is not that. It doesn´t matter the using $state.reload from the view. ¿does anyone get the same issue? Thanks for the support. I attach the function below:
$scope.centerOnMe = function() {
$ionicPlatform.ready(function() {
console.log('Click on Find Me');
if(!map) {
return;
}
$ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
//$state.reload('app.map');
watchPositionId = navigator.geolocation.watchPosition(function(position) {
navigator.geolocation.clearWatch(watchPositionId);
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$scope.latitude = latitude;
$scope.longitude = longitude;
var geolocpoint = new google.maps.LatLng(latitude, longitude);
map.setCenter(geolocpoint);
});
navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
$scope.center = new google.maps.LatLng(lat, long);
$ionicLoading.hide();
console.log("GPS is enabled" + $scope.center);
}, function(err) {
// error
if (err.code == 1) { console.log('GPS disabled! ERROR = ' + err.code); }
else if(err.code == 2) { console.log('GPS is unavailable! ERROR = ' + err.code); }
else if(err.code == 3) { console.log('Error: GPS Timeout! ERROR = ' + err.code); }
$ionicLoading.hide();
}, {
enableHighAccuracy: true, timeout: 20000
}
);
});
};
You better to use this plugin,
cordova plugin add cordova.plugins.diagnostic
It will directly check whether gps is enabled or not.
Fore more details check following ionic forum issues,
Geo location timeout vs location permission error
Get Current Position not working after turning the GPS off on the device even if it turned on again?
Hopes this will help you !!

Google Maps API v3 marker setPosition not working in Safari (sencha touch)

I am using Sencha Touch to develop a mobile version of a Bus Tracker for Boston University. The problem I a running into is that the method setPosition() for a google.maps.Marker is not rendering the position change in Safari or any Mobile browser.
The code set up is as follows:
I initialize an empty markers array
I initialize the map using Ext.Map() (sencha call)
I load data using a JSONP request every 5 seconds interval
Every time I get new data, I check if I have a marker for that bus id inside my markers array
If I don't I create a new marker and push it into my markers array
Otherwise I call setPosition with my new position on that marker in my markers array.
I then run a check to make sure the marker's position got updated to the position received from my JSON request
I have verified (I think) that the marker inside the markers array is getting the new position everytime. Also, in Chrome and Firefox, my buses move (as expected), but in safari and iPhone/Android browsers, nothing moves.
Here is the code snippet:
var markers = {};
var busesFunc = function()
{
Ext.util.JSONP.request({
url: 'http://m.cms-devl.bu.edu/rpc/bus/livebus.json.php',
callbackKey: 'callback',
params: {
},
callback: function(data) {
buses = data.ResultSet.Result;
for (var i = 0, ln = buses.length; i < ln; i++) {
var bus = buses[i];
var position = new google.maps.LatLng(bus.lat, bus.lng);
if(!markers[bus.id])
{
markers[bus.id] = new google.maps.Marker({
map: map.map,
title: 'hello',
clickable: true,
draggable: false,
position: position,
icon: "images/bg.png",
zIndex: 100
});
}
markers[bus.id].setPosition(position);
//markers[bus.id].setIcon("images/bg.png");
//markers[bus.id].setMap(map.map);
//markers[bus.id].setMap(map.map);
if(bus.lat != markers[bus.id].position.lat() || bus.lng != markers[bus.id].position.lng())
{
console.log(bus.id + " " + bus.lat + " " + bus.lng);
console.log(bus.id + " " + markers[bus.id].position.lat() + " " + markers[bus.id].position.lng());
}
}
}
});
}
setInterval(busesFunc, 5000);
You can view the sample here: http://www.bu.edu/nisdev/students/luiscarr/liveBusMobile/
And the whole javascript is called functions.js (I can't post more than one link)
[Sencha Person] markers not showing up is a known bug in the 0.93 beta release. The 0.94 release (current one) has this fixed.
Problem solved by making a unique request every interval. I figured it was a caching problem after some more debugging. So I added a timestamp parameter to the JSONP request and it was all fixed.