Search code examples
androidgpslocation

Get current lat long android


I want to get the Location object on Button press. I know the LocationListener callbacks, however they execute only after a particular time or distance. I want to get Location instantaneously. Are there any methods to do so.


Solution

  • You are welcome to call getLastKnownLocation() on LocationManager to retrieve the last known location for your requested location provider. However:

    • that location may be old
    • that location may be null

    Hence, your code will need to be able to cope with both of those scenarios.