0

Let's say I'm using FusedLocationApi's requestLocationUpdates with interval of 5 minutes, so I will have a cached location data that won't be much older than 5 minutes.

However when the user presses a button for example, I would like to get the current position instead of the cached one to be used. How can I do that?

Question 1: Is there a way to force trigger a location update, so I can get fresh location data instead of potentially 5 minutes old data?

Question 2: FusedLocationApi has a getLastLocation function, which I think will be potentially 5 minutes old too.. since there is no getCurrentLocation function, how can we achieve this?

John
  • 2,820
  • 3
  • 30
  • 50
Bruce
  • 2,357
  • 5
  • 29
  • 50

1 Answers1

0

Sure you can do this.

So in order to start the 5 minute interval updates you either:

Use an instance of a LocationListener

OR

Issue a PendingIntent

With the requestLocationUpdates() method found in the FusedLocationProvider API.

This strategy as you request in the question, would return the "freshest" location.

You are correct, getLastKnownLocation() only works if the system has a cached location. So, to get the most current location, end the updates you initially requested, and then re-request updates with the same intervals.

andrewdleach
  • 2,458
  • 2
  • 17
  • 25
  • The only way to get most current location is to end location update and restart again? Well if that's the only way I guess I have no choice.. but kind of hope there is an easier way. Even the HTML5 geolocation has 'getCurrentLocation' with works side by side with 'watchPosition' which is similar to requestLocationUpdates. :( – Bruce Aug 15 '15 at 07:22