Get the exact GPS location

`private void getLocation () {

        String context = Context.LOCATION_SERVICE;
        LocationManager locationManager = (LocationManager)getSystemService(context);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);

        String provider = locationManager.getBestProvider(criteria, true);
        Location location = locationManager.getLastKnownLocation(provider);
        updateWithNewLocation(location);

        locationManager.requestLocationUpdates(provider, 2000, 5, locationListener);

    }

    private final LocationListener locationListener=new LocationListener()
    {
        public void onLocationChanged(Location location)
        {
            updateWithNewLocation(location);
        }
        public void onProviderDisabled(String provider)
        {
            updateWithNewLocation(null);
        }
        public void onProviderEnabled(String provider)
        {

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

        }
    }`  

My code for getting the location above. But the result of my application is not accurate. I want to get exactly my location. Is there another way?

+3
source share
1 answer

Obtaining an accurate location depends on whether signals are available. E.g. if gps signal is present or not. If there is no GPS, the phone uses wifi or service provider tracking, which is less accurate. So try using google maps and see your location, if you get a more accurate location correction using Google maps, then you are missing something in your code.

, , ACCURACY_COARSE, ACCURACY_FINE. , .

+4

All Articles