How to find out why GPS coordinates are missing in Android?

前端 未结 2 503
别跟我提以往
别跟我提以往 2021-01-29 01:55

I am trying to get a device\'s location information using GPS, but for some reason one of the two coordinates is missing sometimes.

This is the code:

Loc         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 02:26

    Because the GPS isn't always on. getLastKnownLocation will return a location if it knows one and if it isn't too stale. Since nothing else was using the GPS, it doesn't know one. If you need a location, either requestLocationUpdates or requestSingleUpdate, which will turn on the GPS and get a new location.

提交回复
热议问题