Showing posts with label geolocation. Show all posts
Showing posts with label geolocation. Show all posts

Wednesday, October 17, 2018

react-native-background-geolocation not giving exact location while app is in background

Leave a Comment

I have used mauron85/react-native-background-geolocation for tracking the location of the user on my react native app. It is working fine while the app is on fore ground. The location is exact on regular interval. But if the app goes to background, the location is not the same, rather is moved from the previous location even though the device is not moved. Following is my configuration -

BackgroundGeolocation.configure({     desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,     notificationTitle: 'Background tracking',     notificationText: 'enabled',     debug: false,     startOnBoot: false,     stopOnTerminate: false,     locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,     interval: 40000,     fastestInterval: 5000,     activitiesInterval: 10000,     stopOnStillActivity: false,     url: 'http://192.168.81.15:3000/location',     httpHeaders: {         'X-FOO': 'bar'     },     // customize post properties     postTemplate: {         lat: '@latitude',         lon: '@longitude',         foo: 'bar' // you can also add your own properties     } }); 

What should I do to fix this issue?

1 Answers

Answers 1

According the documentation, the location provider you are using BackgroundGeolocation.ACTIVITY_PROVIDER is better suited as a foreground location provider:

ACTIVITY_PROVIDER:

This one is best to use as foreground location provider (but works in background as well). It uses Android FusedLocationProviderApi and ActivityRecognitionApi for maximum battery saving.

So I would try to use DISTANCE_FILTER_PROVIDER instead:

BackgroundGeolocation.configure({      locationProvider: BackgroundGeolocation.DISTANCE_FILTER_PROVIDER }); 

This provider seems to be better suited to be used as a background location provider:

DISTANCE_FILTER_PROVIDER

It's best to use this one as background location provider. It is using Stationary API and elastic distance filter to achieve optimal battery and data usage.

Source:

https://github.com/mauron85/react-native-background-geolocation/blob/master/PROVIDERS.md

Read More

Android location manager error 'Exiting with error onLocationChanged line 152 “1”'

1 comment

I have a location manager in my Android app that sometimes works. Sometimes I'll run the app and it will get location updates (with some errors). Sometimes I'll run it and it will just throw this error every couple seconds without receiving any location updates:

E/IzatSvc_PassiveLocListener: Exiting with error onLocationChanged line 152 "1" 

Here is my class for managing location events:

package com.company.AppName;  import android.app.job.JobParameters; import android.app.job.JobService; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.util.Log;  public class LocationListenerService extends JobService {   private static final String TAG = "LocationListenerService";   private LocationManager locationManager = null;   private LocationListener locationListener = null;   private String locationProvider = null;    public LocationListenerService() {}    @Override   public int onStartCommand(Intent intent, int flags, int startId) {     return START_STICKY;   }    @Override   public boolean onStartJob(JobParameters params) {     Log.i(TAG, "onStartJob");     startLocationManager(params);     return true;   }    @Override   public boolean onStopJob(JobParameters params) {     Log.i(TAG, "onStopJob");     return false;   }    public void startLocationManager(JobParameters params) {     if(locationManager != null) return;      Criteria criteria = new Criteria();     criteria.setAccuracy(Criteria.ACCURACY_FINE);   //    criteria.setPowerRequirement(Criteria.POWER_LOW);     criteria.setAltitudeRequired(false);     criteria.setBearingRequired(false);      locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);     locationProvider = locationManager.getBestProvider(criteria, true);     locationListener = new LocationListener();      if (locationProvider != null) {       Log.v(TAG, "Location provider: " + locationProvider);     } else {       Log.e(TAG, "Location provider is null. Location events will not work.");       return;     }      if (locationListener == null) {       Log.e(TAG, "Location listener is null. Location events will not work.");       return;     }      // Finish job after first time updating location with the server     NativeApp.shared().getLocationData((NativeApp app, String response) -> {       Log.i(TAG, "Received location data response. Finishing job.");       jobFinished(params, true);     });      try {       locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);     } catch (java.lang.SecurityException ex) {       Log.e(TAG, "fail to request location update, ignore", ex);     } catch (IllegalArgumentException ex) {       Log.e(TAG, "network provider does not exist, " + ex.getMessage());     }   }    private class LocationListener implements android.location.LocationListener {     @Override     public void onLocationChanged(Location location) {       if(location == null) {         Log.w(TAG, "onLocationChanged skipped: null location");         return;       }       Log.i(TAG, "onLocationChanged: " + location.toString());       NativeApp.shared().updateLocation(location);     }      @Override     public void onProviderDisabled(String provider) {       Log.i(TAG, "onProviderDisabled: " + provider);     }      @Override     public void onProviderEnabled(String provider) {       Log.i(TAG, "onProviderEnabled: " + provider);     }      @Override     public void onStatusChanged(String provider, int status, Bundle extras) {       Log.i(TAG, "onStatusChanged: " + provider);     }   } } 

Why is this happening? Why do location updates work sometimes but not other times?

EDIT: After giving up for a few hours and rerunning, the app is still throwing the error repeatedly, but after about 10 seconds logs this and starts receiving location updates:

E/XTCC-6.1.2.10: [FDAL_OSListener] handleLocationUpdate:  failed: 2 D/LocationManagerService: incoming location: gps I/LgeGnssLocationProvider: Intent - android.location.GPS_FIX_CHANGE D/LgeGnssLocationProvider: GPS_FIX_CHANGE_ACTION! , mGpsNavigating =true D/LocationManagerService: incoming location: gps 

2 Answers

Answers 1

long milliseconds = 5000; // 5 seconds float minimusDistance = 5.5; // 5.5m distance from current location locationManager.requestLocationUpdates(locationProvider, milliseconds, minimusDistance, locationListener); 

Try this snippet. Hope it will solve your problem.

This is happening only, for this reason, you're not providing a minimum interval and minimum distance to get location updates. That's why you're getting this error.

Here is the link check it out - requestLocationUpdates

Answers 2

This location update gets varies as per the android version. Recently Android introduce background location limits in oreo which says:

While your app is in the foreground, you should receive location updates as frequently as you requested. When your app goes in the background, your app will receive location updates only a few times each hour (the location update interval may be adjusted in the future based on system impact and feedback from developers).

Android recommend to use fused location APIs for below reason, you must consider it for your scenario which says:

If your app needs access to location history that contains time-frequent updates, use the batched version of the Fused Location Provider API elements, such as the FusedLocationProviderApi interface. When your app is running in the background, this API receives the user's location more frequently than the non-batched API. Keep in mind, however, that your app still receives updates in batches only a few times each hour.

Please refer below links for and better approach:

https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesForegroundService/app

https://codelabs.developers.google.com/codelabs/background-location-updates-android-o/index.html#0

Note: The "O" background location limits only kick in when your app is no longer in the foreground.

Please let me know if above two links not working for you.

Read More

Wednesday, September 19, 2018

How to group objects based on longitude/latitude proximity using laravel/php

Leave a Comment

I have a group of users. The user count could be 50 or could be 2000. Each should have a long/lat that I have retrieved from Google Geo api.

I need to query them all, and group them by proximity and a certain count. Say the count is 12 and I have 120 users in the group. I want to group people by how close they are (long/lat) to other people. So that I wind up with 10 groups of people who are close in proximity.

I currently have the google geo coding api setup and would prefer to use that.

TIA.

-- Update I have been googling about this for awhile and it appears that I am looking for a spatial query that returns groups by proximity.

3 Answers

Answers 1

Keep in mind that this problem grows exponentially with every user you add, as the amount of distance calculations is linked to the square of the number of users (it's actually N*(N-1) distances... so a 2000 user base would mean almost 4 million distance calculations on every pass. Just keep that in mind when sizing the resources you need

Are you looking to group them based on straight-line (actually great circle) distance or based on walking/driving distance?

If the former, the great circle distance can be approximated with simple math if you're able to tolerate a small margin of error and wish to assume the earth is a sphere. From GCMAP.com:

Earth's hypothetical shape is called the geoid and is approximated by an ellipsoid or an oblate sphereoid. A simpler model is to use a sphere, which is pretty close and makes the math MUCH easier. Assuming a sphere of radius 6371.2 km, convert longitude and latitude to radians (multiply by pi/180) and then use the following formula:

theta = lon2 - lon1 dist = acos(sin(lat1) × sin(lat2) + cos(lat1) × cos(lat2) × cos(theta)) if (dist < 0) dist = dist + pi dist = dist × 6371.2 

The resulting distance is in kilometers.

Now, if you need precise calculations and are willing to spend the CPU cycles needed for much complex math, you can use Vincenty's Formulae, which uses the WGS-84 reference ellipsoid model of the earth which is used for navigation, mapping and whatnot. More info HERE

As to the algorithm itself, you need to build a to-from matrix with the result of each calculation. Each row and column would represent each node. Two simplifications you may consider:

  1. Distance does not depend on direction of travel, so $dist[n][m] == $dist[m][n] (no need to calculate the whole matrix, just half of it)
  2. Distance from a node to itself is always 0, so no need to calculate it, but since you're intending to group by proximity, to avoid a user being grouped with itself, you may want to always force $dist[m][m] to an arbitrarily defined and abnormally large constant ($dist[m][m] = 22000 (miles) for instance. Will work as long as all your users are on the planet)

After making all the calculations, use an array sorting method to find the X closest nodes to each node and there you have it (you may or may not want to prevent a user being grouped on more than one group, but that's just business logic)

Actual code would be a little too much to provide at this time without seeing some of your progress first, but this is basically what you need to do algoritmically.

Answers 2

... it appears that I am looking for a spatial query that returns groups by proximity. ...

You could use hdbscan. Your groups are actually clusters in hdbscan wording. You would need to work with min_cluster_size and min_samples to get your groups right.

https://hdbscan.readthedocs.io/en/latest/parameter_selection.html

https://hdbscan.readthedocs.io/en/latest/

It appears that hdbscan runs under Python.

Here are two links on how to call Python from PHP: Calling Python in PHP, Running a Python script from PHP

Here is some more information on which clustering algorithm to choose: http://nbviewer.jupyter.org/github/scikit-learn-contrib/hdbscan/blob/master/notebooks/Comparing%20Clustering%20Algorithms.ipynb

http://scikit-learn.org/stable/modules/clustering.html#clustering

Answers 3

Use GeoHash algorithm[1]. There is a PHP implementation[2]. You may pre-calculate geohashes with different precision, store them in SQL database alongside lat-lon values and query using native GROUP BY.

  1. https://en.wikipedia.org/wiki/Geohash
  2. https://github.com/lvht/geohash
Read More

Monday, May 14, 2018

HTML5 mobile app running while phone screen is off?

Leave a Comment

I'm interested in creating an HTML5 geolocation-based web app that could still be operating when the phone screen is off (say, tracking how far you've been running when your phone is in your pocket).

Is there any way to keep the app running but have the screen be off, or have the app run in the background while other apps are being used? Is this possible at least on some of the popular mobile devices out there (newer iOS and Android devices in particular?)

2 Answers

Answers 1

My music app is HTML5 and also needs to run in the background. The support for that varies depending on mobile browser.

  • Safari on iOS: will continue to play one or two songs in the background
  • Native browser on Android: will play one song then stops
  • Firefox on Android: will stop when screen locks or browser loses focus or song ends
  • Dolphin on Android: plays in background! but eventually stops
  • Opera on Android: better background support, Javascript continues to run and music continues to play even when screen is off or Opera is sent to the background, but eventually stops after a couple songs.

As you can see it's hit or miss. Half the time I end up trying to put my phone in my pocket backwards, trying to keep the screen on, until I accidentally press it - totally sucks. I long for the day when the user has more control over running HTML5 apps in the background. If I had to guess I would say that universal support for that is very far off, if it ever even gets traction. I'm being forced toward a native app solution even though I am almost positive Apple will never approve it. In the meantime, I'll remain hopeful and keep testing the latest mobile browsers. Because if it actually happens it will be awesome. :-)

I should also point out that, in my experience, for pretty much all of the above combinations, using HTML5 to simultaneously run javascript, pull network data, and play music will typically turn your phone into an oven and kill your battery pretty quickly. Ugg.

In addition, if you are using jQuery Mobile (which is mostly fantastic), you will see different touch handling on the different browsers. For example, Firefox touch works great, Dolphin is terrible and requires precise touch-and-hold-and-release to get right. That's not directly HTML5's fault, but another issue I'm dealing with.

Here are another developer's interesting thoughts on mobile HTML5.

UPDATE: I just (May 22, 2013) downloaded Opera on my Samsung Galaxy S3 and it has the best HTML5 support so far. For my app, it continues to run javascript in the background, whether the screen is off, or Opera is pushed to the background, for at least a couple songs.

Answers 2

You can use Service Workers:

https://developers.google.com/web/fundamentals/primers/service-workers/

A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. Today, they already include features like push notifications and background sync. In the future, service workers might support other things like periodic sync or geofencing.

To be precise, applications can register a service worker as follows:

if ('serviceWorker' in navigator) {   window.addEventListener('load', function() {     navigator.serviceWorker.register('/sw.js').then(function(registration) {       // Registration was successful       console.log('ServiceWorker registration successful with scope: ', registration.scope);     }, function(err) {       // registration failed :(       console.log('ServiceWorker registration failed: ', err);     });   }); } 

Once the service worker registration is successful, any application logic implemented in sw.js will execute in the background; even if application tab is disabled.

Read More

Wednesday, May 2, 2018

Double message on ios when get geolocation

Leave a Comment

I have created an ios app (Xcode) with a single WebKit View component that loads an external website. This website tries to get the current geolocation with this Javascript: navigator.geolocation.

This all works fine, but the problem is, I get 2 messages:

  1. First a message for the app: 'Allow "NameApp" to access your location while you are using the app?'
  2. Second a message for the webview: 'https://mywebsite.com would like to use your current location'.

I have seen similar questions about this issue, but they all went about a native/offline Cordova app. I have an online app in my Webview.

How can I prevent this double message? Or a workaround for this problem?

0 Answers

Read More

Sunday, February 18, 2018

Adding multiple listeners to navigator.geolocation.getCurrentPosition

Leave a Comment

I am adding three listeners for location updates.

<!DOCTYPE html>      <html>      <body>            <p>Click the button to get your coordinates.</p>            <button onclick="getLocation()">Try It</button>            <p id="demo1"></p>      <p id="demo2"></p>      <p id="demo3"></p>            <script>      var x = document.getElementById("demo1");      var y = document.getElementById("demo2");      var z = document.getElementById("demo3");            function getLocation() {          if (navigator.geolocation) {              navigator.geolocation.getCurrentPosition(showPosition1);              navigator.geolocation.getCurrentPosition(showPosition2);              navigator.geolocation.getCurrentPosition(showPosition3);          } else {               x.innerHTML = "Geolocation is not supported by this browser.";          }      }            function showPosition1(position) {          alert("showPosition1");          x.innerHTML = "Latitude: " + position.coords.latitude +  "<br>Longitude: " + position.coords.longitude;      }            function showPosition2(position) {          alert("showPosition2");          y.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;      }            function showPosition3(position) {          alert("showPosition3");          z.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;      }      </script>            </body>      </html>

In case of Safari and Chrome, all three methods are called. While in case of Firefox, only the last listener method is called.

So what is the default implementation for the location detection feature. Is there a work around to ensure that all the callback methods are called on Firefox.

2 Answers

Answers 1

Firefox had a long history with implementing bugs in geolocation.

What you can do as of now is hack this by monkey patching getCurrentPosition

var getCurrentPosOrg = navigator.geolocation.getCurrentPosition;  function getCurrentPositionMod () {     const listners = [];     function runAllListners(...args) {         listners.forEach(curr => curr(...args));     }     return (cb) => {         listners.push(cb);         getCurrentPosOrg(runAllListners);     } }  navigator.geolocation.getCurrentPosition = getCurrentPositionMod(); 

With this patch, you can simply use getCurrentPosition and do not have to worry about Firefox anymore. If you need to remove listeners you can extend this method to do so as well.

Your snippet will look something like this now.

<!DOCTYPE html>  <html>    <body>      <p>Click the button to get your coordinates.</p>      <button onclick="getLocation()">Try It</button>      <p id="demo1"></p>    <p id="demo2"></p>    <p id="demo3"></p>      <script>      if (navigator.geoloaction) {        var getCurrentPosOrg = navigator.geolocation.getCurrentPosition;          function getCurrentPositionMod() {          const listners = [];            function runAllListners(...args) {            listners.forEach(curr => curr(...args));          }          return (cb) => {            listners.push(cb);            getCurrentPosOrg(runAllListners);          }        }          navigator.geolocation.getCurrentPosition = getCurrentPositionMod();      }      var x = document.getElementById("demo1");      var y = document.getElementById("demo2");      var z = document.getElementById("demo3");        function getLocation() {        if (navigator.geolocation) {          navigator.geolocation.getCurrentPosition(showPosition1);          navigator.geolocation.getCurrentPosition(showPosition2);          navigator.geolocation.getCurrentPosition(showPosition3);        } else {          x.innerHTML = "Geolocation is not supported by this browser.";        }      }        function showPosition1(position) {        alert("showPosition1");        x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;      }        function showPosition2(position) {        alert("showPosition2");        y.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;      }        function showPosition3(position) {        alert("showPosition3");        z.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;      }    </script>    </body>    </html>

Answers 2

Try it using eventWatcher on geolocation API. This a full HTML and JavaScript.

<!DOCTYPE html> <html>     <head>         <title>DEMO</title>         <meta charset="UTF-8">         <meta name="viewport" content="width=device-width, initial-scale=1.0">     </head>     <body>         <p>Click the button to get your coordinates.</p>          <button onclick="startGeolocation() ">Start Geolocation</button>         <button onclick="stopLocation()">Stop Geolocation</button>          <script>             var observerID = -1;              function startGeolocation() {                 //INITIALIZE EVENT WAHTCER POSITIONS                 if (navigator.geolocation) {                     observerID = navigator.geolocation.watchPosition(onSuccess, onError, {                         maximunAge: 60000,                         enableHighAccuracy: true,                         timeout: 20000                     });                  }              }              function stopGeolocation() {                  if (observerID !== -1) {                     navigator.geolocation.clearWatch(observerID);                     observerID = -1;                  }             }              function onSuccess(pos) {                 //THIS EVENT FIRE WHEN POSITIONS HAVE DATA.                 var lat = pos.coords.latitude;                 var lng = pos.coords.longitude;                 var accuracy = pos.coords.accuracy;                 var altitude = pos.coords.altitude;                 var altitudeAccuraccy = pos.coords.altitudeAccuracy;                 var heading = pos.coords.heading;                 var spped = pos.coords.speed;                 var timeSpan = pos.coords.timestamp;                 //ADD YOU CODE HERE...             }              function onError(error) {                 switch (error.code) {                     case error.PERMISSION_DENIED:                          alert("USER NOT ACCEPTED PERMISSION.");                         break;                     case error.POSITION_UNAVAILABLE:                         alert("POSITION NOT AVAIBLE.");                         break;                     case error.TIMEOUT:                          alert(true, "TIME OUT.");                         break;                     case error.UNKNOWN_ERROR:                         alert(true, "OTHER ERROR.");                         break;                 }              }          </script>     </body>  </html> 
Read More

Tuesday, October 17, 2017

cdn: proxy request to specific origin based on ip geolocation

Leave a Comment

I have a service with a few origin servers, each in a different continent. Every client request goes through a cdn that proxies to these servers. About half of requests are cacheable and the other half are not. It doesn't matter much which of the origins serves the cacheable responses because the distributed CDN will handle serving that response from the closest possible POP for those requests in the future (until cache expiration). However, for uncacheable responses, I'd like for the closest origin to the user to respond to requests that the CDN is proxying.

Is there such a feature that some CDNs have whereby you can specify something like: "make a best effort to geocode the request based on ip, if the ip is from continent north america use noram.originfoo.com, if the ip is from continent europe use eu.originfoo.com, etc"?

Maybe the architecture should instead be that DNS resolution chooses a CDN hostname based on the client ip and the CDN has different entries whereby one region specific-CDN hostname maps to one origin hostname.

2 Answers

Answers 1

You could use an existing services that does this of course, AWS for sure can do this. But if you want to implement this yourself you would basically need to find the location of the caller via their IP, and according to that send them the URL to the closest location.

Answers 2

Take a look fastly CDN solution. It uses varnish and allows for vcl rules to be used by the customer (see their docs). Here's a guide that appears to be doing what you need:

Fastly allows you to change origin servers based on the user's geographic location. This is useful when you need to serve different content to users who are in different locations. For example, you could change origin servers to serve a restricted version of your website to users in a different country.

Read More

Thursday, July 28, 2016

Can I check devices location is open or close on React Native

Leave a Comment

Can I check devices location is open or close before using geolocation? I want to show alert message like App need to run your location, please open your devices location, when devices location is close.

Can I navigate to go native location setting both IOS and Android?

Like example -

componentDidMount() {   // Check condition device location is open or close.   if( DevicesLocation === 'close' ) {      alert('App need to run your location, please open your devices location');      // other process    } else {      navigator.geolocation.getCurrentPosition(         (position) => {            var initialPosition = JSON.stringify(position);            this.setState({ initialPosition});         },         (error) => console.log(error.message)      );   } } 

1 Answers

Answers 1

I think you can use

navigator.geolocation.getCurrentPosition(    (position) => {     //do stuff with location    },    (error) => {      this.setState({locationEnabled: false}),    },    {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}  );

For opening settings from your app, I think you will have to get your hands dirty with native code :D

Read More

Sunday, March 27, 2016

GPS coordinates in background in cordova app

Leave a Comment

I'm currently doing a hybrid app using ionic/cordova. The app needs functionality where it pings our backend with its location every 1 minute or so and the backend API will answer if anything interesting is nearby. If the answer is yes the app will queue a local notification which hopefully will make the user open the app. This functionality is needed when the app is in background mode and even when the phone is locked. The app needs to be able to be deployed to both app store, google play and eventually windows phone.

I'm currently using a combination of these three plugins:

https://www.npmjs.com/package/cordova-plugin-geolocation - for location https://github.com/katzer/cordova-plugin-background-mode - for bg mode https://github.com/katzer/cordova-plugin-local-notifications - for local notifications

This currently works on Android when the device is not locked (so it works in foreground and background mode) but when the device is locked it is unable to get the GPS coordinates.

My code currently looks like this:

        // Enable background worker                   (cordova as any).plugins.backgroundMode.enable();     intervalPromise = $interval(intervalWork, 30000, 0, false);      function intervalWork() {         $log.log('Trying to fetch pos');          var options = { maximumAge: 30000, timeout: 30000, enableHighAccuracy: false };          navigator.geolocation.getCurrentPosition(success,             err,             options);     }      function success(pos) {         $log.log("lat: " + pos.coords.latitude + " long: " + pos.coords.longitude);          var Checkin = $resource(ApiDataEndpoint.url + 'checkin/:lat/:lng/', {});          var res= Checkin.get({ lat: pos.coords.latitude, lng: pos.coords.longitude });                 if (res) {                   $cordovaLocalNotification.schedule({                     id: 1,                     title: 'test',                     text: 'test',                 }).then(function(result) {                     $log.log("ok");                 });             };          } 

So... my questions are:

1) How to get the solution to work when my device is locked (the getCurrentPosition is called even when device is locked but returns timeout)?

2) Is it possible to get this solution to work on iOS?

3) Will an app made this way be approved in google play and app store?

4) If the project is doomed what are my alternatives?

I really need help on this one!

2 Answers

Answers 1

This plugin has a great guide for how to use a meteor server and cordova to do what you need:

zeroasterisk/meteor-cordova-geolocation-background

It configures automatically with both android and iOS. For windows phone I don't know.

  1. Meteor configures this Plugin in Cordova (you have to configure)
  2. Meteor configures this Plugin in Cordova (you have to configure)
  3. Meteor can trigger the Background service to get Geolocation (GPS) details
  4. The Cordova Background service periodically POSTs it's data to the Meteor server (not to the client Cordova instance)
  5. Meteor Server can update a Collection (or anything else)
  6. Meteor Client syncs with the server

Answers 2

So I currently have an app that addresses all the issues you listed above and here's the plugin I'm using:

https://github.com/mauron85/cordova-plugin-background-geolocation

  1. The plugin makes use of watchPosition() not get getCurrentPosition() as this one takes too long to constantly ping the device and consumes more battery power.

  2. This will definitely work for Android & iOS but IMHO it works better for Android than the latter, as far as precision and the keep alive functionality.

  3. I got it into Google Play no problem, Apple does allow this plugin, there are a number of apps using this plugin in the Apple store but Apple will probably initially reject it and ask the apps intention of background usage, you will then have to make an appeal as for what the app is doing in the background and make sure that it doesn't run indefinitely (this was my experience).

    a. You're going to also want to make sure you point out to the Apple peeps that there is a way for the User to turn the background geolocation tracking off. I'm assuming there is? That's their main issue with the usage of the plugin.

Good luck.

Read More