locationManager.getLastKnownLocation() return null

后端 未结 5 1224
天命终不由人
天命终不由人 2020-12-16 13:32

i dont understand why locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); return the location null. I gave all permission but its reutning

5条回答
  •  清歌不尽
    2020-12-16 13:51

    You can request location updates like this

    mLocationManager.requestLocationUpdates(myProvider, 0, 0, locationListener);
    

    then on the first callback in locationListener.onLocationChanged set your coordinates. Just don't forget to call mLocationManager.removeUpdates(locationListener)

提交回复
热议问题