-1

I am using a MapView to display the current position of the user. The user is supposed to be able to move around and a blue line corresponding to his/her path will be displayed.

I am using the getCurrentLocation() function to get the location every 5 secs and then update the path on the map using a polyline.

My question is what is the best way (resources wise) to get the location considering that the MapView is already active and has the location of the device.

Should I be using -

  1. getLastLocation()
  2. getCurrentLocation() itself
  3. getMyLocation() (deprecated) that can be called directly on my GoogleMap object
Ayush
  • 91
  • 1
  • 10

1 Answers1

0

Seems to depend on your specific use case.

Returns a single current location fix on the device. Unlike getLastLocation() that returns a cached location, this method could cause active location computation on the device. A single fresh location will be returned if the device location can be determined within reasonable time (tens of seconds), otherwise null will be returned.

This method may return locations that are a few seconds old, but never returns much older locations. This is suitable for foreground applications that need a single fresh current location.

Background apps calling this method will be throttled under background location limits, so background apps may find the method returns null locations more often.

link

Justin Poehnelt
  • 2,992
  • 1
  • 19
  • 23