Android LocationManager.getLastKnownLocation() returns null

前端 未结 2 1620
醉酒成梦
醉酒成梦 2020-11-29 04:13

So I\'m trying to sample the gps coordinates just once in an application. I don\'t want to create a LocationListener object to constantly get gps updates. I want to wait u

2条回答
  •  日久生厌
    2020-11-29 04:54

    Try using the MyLocationOverlay , create a runnable that does what you need to do with that GPS location, and pass it to

    boolean     runOnFirstFix(java.lang.Runnable runnable)
              Queues a runnable to be executed as soon as we have a location fix.
    

    and then disable the location updates for the MyLocationOverlay.

    Edit: The reason the location is null is because at the time that code is run, no geofix has been received.

提交回复
热议问题