Why does the LocationManager does not have a lastKnown location?

后端 未结 2 396
星月不相逢
星月不相逢 2021-01-23 12:15

I want the location of user and that too just once after that user navigates on his own

locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 12:28

    The getLastKnownLocation method will only return a location if the gps LocationProvider has stored a location somewhere. If the user has not yet used the gps on his device long enough to obtain a valid GPS fix the method will return null.

    Even if you retrieve a location check the time of the location, there is no guarantee that the location isn't very very old.

提交回复
热议问题