android - Is it possible to trigger location change without battery drain? -


in application need update user's location when entering city.

so example:

  1. user lives in citya
  2. user travels citya cityb
  3. a function should triggered.

i see following functions provided google play services:

  1. public abstract location getlastlocation (googleapiclient client)

  2. public abstract pendingresult<status> requestlocationupdates (googleapiclient client, locationrequest request, locationlistener listener)

the problem is:

i need track user's city location changes continuously, not when user using app.

how without draining battery fast?

you can use broadcast receivers this. there documentation @ https://developer.android.com/reference/android/content/broadcastreceiver.html.

private static final locationrequest request = locationrequest.create() .setfastestinterval(60000) // in milliseconds .setinterval(180000) // in milliseconds .setpriority(locationrequest.priority_low_power);

'@override public void onconnected(bundle bundle) {     locationservices.fusedlocationapi.requestlocationupdates(         mgoogleapiclient,         request,         this);  // locationlistener }` 

use fusedlocationapi , go.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -