How to full fill Location() by your own value?

Viewed 40

I couldnt understand how to fill something like this by my own values without gps connection:

val lastLocation: Location? = Location()

When we input provider like this:

val lastLocation: Location? = Location(LocationManager.GPS_PROVIDER)

lastLocation values are null.

On the one hand Location() has its own constructor(as I understand) and even method set(), but l I can't figure out how to fill it with my own values.


Maybe someone can show an example or provide a useful link?

1 Answers

Here is the most convenient way in order to fill your data, that I have found:

  lastLocation: Location? = Location(LocationManager.GPS_PROVIDER).apply {
        latitude = 56.491232323
        longitude = 84.973284721
        speed = 12.2f
        altitude = 86.4
        accuracy = 11.1f
        bearing = 90.0f
        bearingAccuracyDegrees = 1.42f
    }
Related