0

I am facing a issue with getting current location in Android.

I am using FusedLocationAPI of android. But the latitude and longitude which I am getting is not accurate. I pasted that credentials on google maps, and it show's me place that is different from my accurate location.

I also tried to get location updates and verified the accuracy by Location.getAccuracy() , here the the minimum accuracy which I gets is 10 meters. Here I am using Fine Location as a permission. So here my question is , how can I get my accurate location, In other words accuracy less then 5 meters.?

My Code is

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .enableAutoManage(this, this)
                .build();

    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setSmallestDisplacement(1);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

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

 @Override
public void onLocationChanged(Location location) {
    Toast.makeText(MainActivity.this,";-"+location.getAccuracy(),Toast.LENGTH_LONG).show();
    if(location.hasAccuracy() && location.getAccuracy()<lastLocationAccuracy){ 
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    }
}
Jay Vyas
  • 2,674
  • 5
  • 27
  • 58

2 Answers2

1

I search a lot and i can not find anything about less then 10 accuracy using fused location API.

if you seen the Google IO presentation, a chart was presented showing effect of different priorities of the recognition algorithm as tested multiple times on Galaxy Nexus.

Google IO

If you wanna get less then 10 accuracy then you can use GPS but it was also depend on the device , GPS, WiFi, Cell Tower, Bluetooth etc...

If the GPS hardware can receive WAAS correction it can do better, about 7.6m worst case, 1-2m best case.

Arpit Patel
  • 7,212
  • 5
  • 56
  • 67
1

How can I get my accurate location, in other words accuracy less than 5 meters?

The short answer

When working with location, it is important to understand that you may request a certain accuracy, but you're not guaranteed to get that accuracy in actual location updates.


You cannot generally expect to get location updates with an accuracy < 5m. It depends on a number of factors, most importantly the capabilities of your device and your physical surroundings.


The long answer

The FusedLocationApi does a lot of magic behind the scenes. Among other things it tries to figure out which providers to use (GPS, WiFi, Cell Tower, Bluetooth etc.). Each of these providers has pros and cons in terms of accuracy, update frequency and battery drain. It then fuses the info from different providers, hence the name.

Example 1: If you're in an urban canyon in New York City, you will have a really hard time to obtain a good and accurate GPS fix. On the other hand, there will be plenty of WiFi networks around, which have been mapped and georeferenced by Google. So you're likely to get a quick location fix. The accuracy will depend on the density of WiFi networks and more importantly on the density of walls/buildings. I wouldn't expect to get anything more accurate than 15-30 meters here.

Example 2: If you're out in the desert somewhere, it's the other way around. Most likely, there won't be any WiFi networks nearby, but you will get a crystal clear GPS fix. Here you could expect location updates with < 5m accuracy.

Your setup looks correct. Choosing a high update rate and a high priority will ensure that GPS is used as a provider (if available on the device). Make sure you test your app outside, with a clear view of the sky. If you keep receiving really far-off locations, test with another device. If it still doesn't work, then something is wrong with your code. You may want to use a utility class such as the LocationAssistant (Full disclosure: I am the author of that project), to ensure you set everything up correctly.

Misconceptions

Finally, I would like to clarify two common misconceptions that I saw in other comments:

  • As stated in the documentation, Location.getAccuracy() will return the estimated accuracy of a location reading. This is a best guess (often based on a Gaussian error model) which may be far off. I have seen situations in which the fused location claimed an accuracy of 3m and it was really more than 100m off. So do not rely on it for critical functionality.

  • The ACCESS_FINE_LOCATION permission is perfectly sufficient for getting high-accuracy updates. There is no need to additionaly specify ACCESS_COARSE_LOCATION.

KlaasNotFound
  • 1,035
  • 10
  • 15