0

I am using google fusedLocationapi for fetching lats and longs. Now i am having a problem here actually i want to get lat and long only at my button click event. That's why i think i don't need to request for location updates which can save my user's battery power. Now in the fusedlocationapi example every one use

mLocationRequest.setInterval(10000); // Update location every second
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);

I ran my code without using above two lines of code and i fetched my location using below code

mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

But it is showing same lats and longs, now can any one please tell me how can i fetch lats and longs using fusedlocationapi without requesting for location updates.

Prakash Kumar
  • 829
  • 1
  • 15
  • 32
  • I am using https://github.com/mcharmas/Android-ReactiveLocation and it works well for me for continuous updates. I have however seen examples of what you want, where they request location updates for a short while and pick the best as the result. The problem with the method you use is that it simply returns the last known location if it has one that I fairly recent. – cYrixmorten Sep 29 '16 at 16:45
  • yes everytime i get last location but not the updated one can you please tell me or direct me to the examples you have seen. – Prakash Kumar Sep 29 '16 at 16:47
  • There is an `isBetterLocation` example here: https://blog.codecentric.de/en/2014/05/android-gps-positioning-location-strategies/. Using the library I linked before, you can request location updates for 5 - 10 - 20 seconds, depending on your needs, then use such strategy as described in the blog to pick the best of the updates to determine user location. – cYrixmorten Sep 30 '16 at 10:50

0 Answers0