Android problem finding out how recent latest GPS fix is

前端 未结 2 1271
花落未央
花落未央 2020-12-02 00:15

My app uses LocationListener to keep track of the current location. So long as the GPS Provider is providing regular fixes this works well. However, I want my app to alert t

2条回答
  •  渐次进展
    2020-12-02 01:01

    GPS location time comes independently of your network provider time/device time. System.currentTimeMillis() will give you device time set on your device.

    If you want to know how recent the point is you can:

    1. Synchronize both the times ( GPS and device ) in your code at application start by taking the difference between both as soon as you get first GPS location update. At that instant query device time and see what's the difference in both. Save this difference in variable.

    2. Use this as a correction factor in subsequent location updates to know the exact time based on the reference frame you need. ( Device time or GPS)

    Also I had found that using NETWORK as location provider you may get device time only. So if you are listening on updates from both ( GPS and network ) , you may also need to distinguish this using location_obj.getProvider() and filter out GPS provider.

提交回复
热议问题