The question is how to organize automatic determination of the location of the device with high accuracy. It is clear that we catch the change of coordinates in onLocationChanged, but how do you know that the coordinates are exact and do not require further clarification? Here is a method

LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this);

And such a LocationRequest

protected void createLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(10 * 1000); mLocationRequest.setFastestInterval(5 * 1000); mLocationRequest.setNumUpdates(3);//как пример mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); }

With such a LocationRequest, the device will insert the GPS or GLONASS and will position itself. The essence of the question is when the first time onLocationChanged works, it’s not a fact that the coordinates will be accurate, for example, the next update may be a clarification, just like the third coordinate change may be less accurate than the second.

    1 answer 1

    Location has a float getAccuracy() method that returns the expected error of this location in meters, or 0.0 if there is no accuracy data.

    The system cannot know in advance whether it can clarify the coordinates compared to what it is now, because it depends on external conditions, and not on the system itself. Navigation satellites can be seen a little, the signal is bad, whatever.


    You can set the default accuracy threshold to the expected “tolerable accuracy” of navigation that makes sense for the application. If there is no accuracy data at all, the application will still work, since the error will be “supposedly zero”.

    It is also worth making the possibility of its manual settings for the sad cases.

    You can also dodge and do autotune, which will automatically increase the allowable error if inaccurate data will be received for a long time.

    However, this is an assumption about the application.

    • Correctly, I realized that getAccuracy () is an accuracy threshold, that if this accuracy falls into this accuracy, the system will stop updating coordinates itself? In general, the essence of the issue is that for sure it needs a UI and that the user himself confirms his location. - Ilya Shashilov
    • @ IlyaShashilov is not, Location is a specific point, a specific position, known at the moment. An object of this type flies to onLocationChanged . Subsequently, the Location may arrive with a different accuracy. Whether above, below, how to know. - D-side
    • It's clear. Well, I have mLocationRequest.setNumUpdates (3) - this means that the system will stupidly cut off the GPS after three updates. How to make it beautiful so that the system itself realizes that the current update is accurate, and you can cut down the GPS, otherwise the battery is not eternal :) In some cases, one update may be enough, and in some 3 ex will be enough. It is clear that it depends on the external conditions. For the case of the bunker, you can set the timer to cut off the GPS. - Ilya Shashilov
    • @ IlyaShashilov described above. Either when the accuracy is reached, above which there is no longer any sense, or if the accuracy has not increased in N time. As an option. - D-side
    • OK. I will try in practice, I hope then it will become clearer :) - Ilya Shashilov