Location from GPS_PROVIDER or NETWORK_PROVIDER in

2019-07-23 21:05发布

问题:

What I am trying to do

  • Get users location at specified interval using a Service so that as long as application is running Location can be retrieved

Problem I am facing

  • Even if I am in same location for long time, each time the Latitude , Longitude changes with different Accuracy levels
  • Due to this, even if user has not changed his location, if I am plotting the Location in GoogleMap it makes jump to very near by places being my zoom level 18.0f
  • mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLon, 18.0f));

I have tried approaches mentioned in stackoverflow Link One and stackoverflow Link Two

But even though I am sitting in the same location and retrieving location in regular interval, the Lat and Lon differs like this , see the highlighted values at end of every lat lon:

Latitude: 12.8379283 Long: Longitude: 77.6647266

Latitude: 12.8379233 Long: Longitude: 77.6647368

Latitude: 12.8379285 Long: Longitude: 77.6647506

Latitude: 12.8379245 Long: Longitude: 77.6647546

  • Now I experimented with this approach GITHub reference

but still every time the Accuracy differs and Lat Lon slightly changes.

As my code trials are exactly same as mentioned in link's I am not just copy pasting here. How can this be resolved

回答1:

The accuracy of the GPS is not absolute, so even a static device will show different locations in successive readings. Try the following:

  1. You can add a method that detects if the mobile is static or not, by reading he accelerometer - if the delta between two readings is bigger than some threshold - the device is moving. If it's too small - it's not moving. To determine the delta - put the device on a table and see what values you get.
  2. Ignore close readings - Take the first reading with good accuracy (<20m or other value you determine) and use it as a reference - if the next reading gives a very small distance, close to the reference (<10m or other value), ignore it. If it's bigger - set it as the new reference.


回答2:

try to set Accuracy_HIGH and set time limit and distance limits.
try using google places fused api for location related work. Refer here: -http://coderzpassion.com/android-location-using-google-play-services/