TMH
TMH

Reputation: 6246

Methods for getting the most accurate location

In my app I have a location listener which logs out the location accuracy and puts a marker on a map where I am, however the accuracy is always around the 900 mark, and my location is between 0.2 and 0.5 miles off where I actually am. If I load up Google Maps it gets my location within a few meters.

What method's are there for ensuring an accurate location? I have these permissions in my Manifest

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

And here's my listener

LocationListener searchUsingLocation = new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    float accuracy = location.getAccuracy();
                    Log.d("FUApp", "Location changed: "+accuracy);
                    List<JSONObject> centres = sortVenuesByNearest(location);
                    try {
                        populateList(centres);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    setRefreshActionButtonState(false, R.id.search_using_location);

                }

                @Override
                public void onStatusChanged(String s, int i, Bundle bundle) {

                }

                @Override
                public void onProviderEnabled(String s) {

                }

                @Override
                public void onProviderDisabled(String s) {

                }
            };
            Log.d("FUApp", "Starting request");
            locationService.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 50, 5, searchUsingLocation);

EDIT: Also my phone settings, Access location on, GPS Satelites is on and Wi-Fi & mobile network locations is on too.

Upvotes: 1

Views: 14953

Answers (3)

Devrim
Devrim

Reputation: 15533

You are only listening LocationManager.NETWORK_PROVIDER. If you want more accuracy you must listen other providers, but wait a minute:)

Google improved its map and location management with fused location provider. https://developer.android.com/google/play-services/location.html

With fused location; you do not need to query best location provider. If you want to get high accuracy you only set it to the location request.

setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) 

Upvotes: 4

Sulabh Gajjar
Sulabh Gajjar

Reputation: 501

I had same issue before few days ago.I have changed the setPriority() to PRIORITY_BALANCED_POWER_ACCURACY. And Its give me accurate location up to 10 Meters.

Instead of this line mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

Add this line mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

My suggestion is to use PRIORITY_BALANCED_POWER_ACCURACY.

Upvotes: 0

Philip Sheard
Philip Sheard

Reputation: 5815

Android tries to mask the reality of the hardware from us, but in practice there are only two location providers: GPS and network. GPS location is slow and not all devices have it, but it is accurate. Network location is faster and is supported by almost all devices, but it is less accurate.

If you know which provider you want, you are better off specifying it explicitly. It your app can work with either provider, you may want to ask the user to choose which he wants to use. Do not rely on what Android tells you, because most cheap devices are horribly provisioned, and may lie to you.

Upvotes: 11

Related Questions