How to get current location in android 7?

前端 未结 2 652
梦谈多话
梦谈多话 2021-01-23 10:10

I\'m trying to get current location in android and its OK when i\'m using on android M or lower, But when i run my application on android N, location is null and when i want get

相关标签:
2条回答
  • 2021-01-23 10:13

    To get the last known location all your have to do is call

    mLocationClient.getLastLocation(); once the location service was connected.

    read how to use the new location API

    http://developer.android.com/training/location/retrieve-current.html#GetLocation

    0 讨论(0)
  • 2021-01-23 10:23

    and its OK when i'm using on android M or lower

    No, it is not. getLastKnownLocation() frequently returns null, on all versions of Android.

    getLastKnownLocation() is an optimization. Use it, but be prepared to rely upon onLocationChanged() for when getLastKnownLocation() returns null or an out-of-date value.

    This is covered in the documentation, as well as in books and courses on Android app development.

    0 讨论(0)
提交回复
热议问题