Mohad Hadi
Mohad Hadi

Reputation: 1986

android how get current location with 7 or more digits Accuracy

I have this from LocationListener but this code just give 4 or 5 digits accurate, like 43.1234, I want more accuracy like 43.1234567, so how to do that?

private LocationListener mLocationListener = new LocationListener() {
    @Override
    public synchronized void onLocationChanged(Location l) {
        strLatLng = l.getLatitude() + "," + l.getLongitude();

    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

};

It's not important if it has another way and not in LocationListener, I get this accuracy just when I write on google map setOnMapClickListener like this:

Is there anyway else get this accuracy?

googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        public void onMapClick(LatLng CLICKED_LOC) {
            double lx,ly;
            lx = CLICKED_LOC.latitude;
            ly = CLICKED_LOC.longitude;
            strLatLng = lx+","+ly;
        }
    });

Upvotes: 3

Views: 4588

Answers (2)

blackkara
blackkara

Reputation: 5052

I have this from LocationListener but this code just give 4 or 5 digits accure, like 43.1234, I want more accuracy like 43.1234567, so how to do that?

Firstly, i don't think that digit count would affect accurateness exactly. You should be relying on accuracy value of location instead. For example, locationX (digits less than 6, accuracy 8) would be reliable than locationY(digits more than 6, accuracy 10)

Secondly, GPS will give you more accurate location, but i strongly suggest using fused location provider. Because it combines some factors under the hood, and produces the best location for your wish (e.g, PRIORITY_HIGH_ACCURACY)

Thirdly, i saw your comment, "I have no choice force user tap on map to get his/her exact location with more than 10 digits". I don't know the scenario of your app, but this sounds a bit big. I suggest reading this answer, https://gis.stackexchange.com/a/109178/77725

// https://gis.stackexchange.com/a/109178/77725
Decimal Places   Aprox. Distance    Say What?
1                10 kilometers      6.2 miles
2                1 kilometer        0.62 miles
3                100 meters         About 328 feet
4                10 meters          About 33 feet
5                1 meter            About 3 feet
6                10 centimeters     About 4 inches
7                1.0 centimeter     About ½ an inch
8                1.0 millimeter     The width of paperclip wire.
9                0.1 millimeter     The width of a strand of hair.
10               10 microns         A speck of pollen.
11               1.0 micron         A piece of cigarette smoke.
12               0.1 micron         You're doing virus-level mapping at this point.
13               10 nanometers      Does it matter how big this is?
14               1.0 nanometer      Your fingernail grows about this far in one second.
15               0.1 nanometer      An atom. An atom! What are you mapping?

Upvotes: 3

TwinkalGajera
TwinkalGajera

Reputation: 84

There are 3 types of location provider in Android :

  1. GPS_PROVIDER
  2. NETWORK_PROVIDER
  3. PASSIVE_PROVIDER.

Use : locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, new MyLocationListener());

you will get precision upto 14+ decimal places.

But if you use fusion of them like this :

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

you will get precision upto 6 to 7 decimal places. try it !!! ref

But note few things here that, GPS Provider takes time to fetch location while Google Location is much faster as it gets data from API call to its google server database.

GPS works offline while google provider gets the location via mobile or wifi data.

Upvotes: 6

Related Questions