Mobile Apps | Fluctuation in the latitude and longitude values for the current location

|
| By Webner

In mobile applications development tracking lat/long of the current location is one of the most commonly used features. To achieve such functionality we mainly use three types of providers which are:

1. GPS providers

2. Network Providers

3. Sim Card or Offline providers

But when we use any of them to get the latitude/longitude for current location we face the problem of fluctuation in the values even without moving the device. This problem is primarily because of following:

Using multiple providers for the same purpose in a single app i.e. GPS provider along with network provider or offline provider, and they all work on different aggressive settings, which results in fluctuating values of latitude and longitude.

Switching between GPS and Network Location is not a good idea (network will introduce jumps of e.g up to 1000m or even more). This concept can be understood in depth by learning these technologies but just for an overview we can say that the Gps system works on electromagnetic waves depending on the global time and distance variables, whereas tracking device position through network provider uses Radio waves (which is again just a part of electromagnetic terminology with lesser accuracy as these waves are also dependent on the environmental factors). And for same purpose offline providers use Cell Id, Ultrasonic waves etc.

The solution is to understand your needs and use only one of these methods, probably GPS providers for better accuracy.

For Android code we should use the LocationManager.requestLocationUpdates() method to set time and distance properties that affect how often the device will request a location update:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,listener);

In above code the time and distance properties are both set to zero, which is the most aggressive setting. This setting can result in your app accessing the GPS provider as often as 50 – 60 times or more per minute. So you can change these parameter values to desired values as :

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10, locationListener);

For first-time location snapshots app can run until a minimum accuracy value is received and then it can turn off the location listeners using the Location.requestSingleUpdate() method.
Once the device starts providing real-time locations, we can check the accuracy of each result and consider rejecting those out of accuracy range we desire. Here’s a pseudo-code snippet showing how to check the accuracy of each GPS location result:

public void onLocationChanged(Location location)
{
/*
example@example.com
Mobile Apps | Fluctuation in the latitude and longitude values
getAccuracy() will  Get the estimated accuracy of this location, in meters.
*/
     if(location.getAccuracy() < 100.0 && location.getSpeed() < 6.95)
     {
      // Values are still fluctuating.
      }
     else
     {
      //Continue listening for a more accurate location
     }
}

Leave a Reply

Your email address will not be published. Required fields are marked *