Skip to content Skip to sidebar Skip to footer

Android Google Maps Api Gps Location Is Changing Even When Device Is At The Same Place

I am using Google Maps API for my application. My GPS location is changing even when device is at the same place, the location is said to be updated every 6s and thus it keeps upda

Solution 1:

Did you try to add minDisplacementDistance to your LocationRequest ?

privateLocationRequestcreateLocationRequest() {
    LocationRequest mLocationRequest = newLocationRequest();
    mLocationRequest.setInterval(6000);
    mLocationRequest.setFastestInterval(1000);
    mLocationRequest.setSmallestDisplacement(200); 
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    return mLocationRequest;
} 

If you will set this parameter (by default it's equal 0) , on LocationChanged listener will not be called each time if your new position which GPS find is inside 200 meters radius of previus found position.

Right now your onLocationChange listener is called each 6 seconds and the minimum distance is equal 0. Since GPS is not 100% correct, you will get a lot of different positions. After you change smallestDisplacement to higher, that's will be not called so often.

Solution 2:

Sometimes due to low accuracy settings, data will receive from Wifi networks. Check Setting/Location/Use Wireless networks check box on your android phone.

Solution 3:

Did you tried mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

When i am using LocationRequest.PRIORITY_HIGH_ACCURACY the Gps is always using and always changing in buildings . And i changed accuracy then the location changing less than.

You can take a look at this :

/*
    Priority                update interval      Battery drain per hour (%)     Accuracy
    HIGH_ACCURACY           5 seconds                   7.25%                   ~10 meters
    BALANCED_POWER          20 seconds                  0.6%                    ~40 meters
    NO_POWER                N/A                         small                   ~1 mile

*/

And using :

publicstaticvoidcreateLocationRequest() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_INTERVAL);
    mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
}

privatestaticint UPDATE_INTERVAL = 20000; // 20 secondprivatestaticint FASTEST_INTERVAL = 10000; // 10 secondprivatestaticint DISPLACEMENT = 50; // minimum change to get location 

Solution 4:

Remove these two lines from your code:

mLocationRequest.setInterval(6000);
mLocationRequest.setFastestInterval(1000);

Post a Comment for "Android Google Maps Api Gps Location Is Changing Even When Device Is At The Same Place"