1

getting lat,lon values one or two buildings away and not getting the exact lat and lon values.I am trying to get atleast one or two meter accuracy for Latitude and longitude values for Current Location.This is the code

public class GPSLocatorActivity extends MapActivity implements OnClickListener {
MapView mapView = null;
MapController mapController = null;
MyLocationOverlay whereAmI = null;
private Button bdiffaddr, bnext;
MyLocation myLocation;
GeoPoint p = null;
MapController mc = null;
public static LocationManager locManager;
protected ProgressDialog progressDialog;
public static double latitude, longitude;
public String TAG = "GPSLocatorActivity";

protected boolean isLocationDisplayed() {
    return whereAmI.isMyLocationEnabled();
}
protected boolean isRouteDisplayed() {
    return false;
}
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gpslocation);
    initialiseviews();
    // onclick listeners
    onclicklisteners();
    currentLocLatLong();
    // new GoogleMapAsyncTask().execute();
    GPSLocatorActivity.this.runOnUiThread(new Runnable() {
        public void run() {
            mapView = (MapView) findViewById(R.id.mapView);
            mapView.setBuiltInZoomControls(true);
            mapController = mapView.getController();
            mapController.setZoom(15);
            whereAmI = new MyLocationOverlay(GPSLocatorActivity.this,
                    mapView);
            mapView.getOverlays().add(whereAmI);
            mapView.postInvalidate();
        }
    });

}
public class GoogleMapAsyncTask extends AsyncTask<Void, Void, Void> {
    protected Void doInBackground(Void... voids) {
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
        mapController = mapView.getController();
        mapController.setZoom(15);
        whereAmI = new MyLocationOverlay(GPSLocatorActivity.this, mapView);
        mapView.getOverlays().add(whereAmI);
        mapView.postInvalidate();
        return null;
    }

}
private void currentLocLatLong() {
    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100L,
            100.0f, locationListener);
    Location location = locManager
            .getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    }
}
private void updateWithNewLocation(Location location) {
        String latLongString = "";
    Log.d("Lat: + latitude + \nLong: + longitude", "Lat:" + latitude
            + "\nLong:" + longitude);
    if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        latLongString = "Lat:" + latitude + "\nLong:" + longitude;
    } else {
        latLongString = "No location found";
    }
}
public void onResume() {
    super.onResume();
    whereAmI.enableMyLocation();
    whereAmI.runOnFirstFix(new Runnable() {
        public void run() {
            mapController.setCenter(whereAmI.getMyLocation());
        }
    });

}
public void onPause() {
    super.onPause();
    whereAmI.disableMyLocation();
}
public void onLocationChanged(Location location) {
    if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        @SuppressWarnings("unused")
        String currentLocation = "Lat: " + latitude + " Lng: " + longitude;
        // txted.setText(currentLocation);
        p = new GeoPoint((int) latitude * 1000000,
                (int) longitude * 1000000);
        mc.animateTo(p);
    }
}
public 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) {
    }
};

please help if anyone has idea how to get the accuracy upto one or two meter distance.
Pradeep
  • 129
  • 3
  • 10

1 Answers1

2

Sorry, you cannot increase accuracy by programming. Accuracy increases with receiving more satellites or by using a better GPS hardware or extended systems (like WAAS using in aviation). Additionally, reception is better outside of buildings and away from any obstacles in the direct line of sight to the satellites.

To determine how many satellites you are receiving, you may look here: https://stackoverflow.com/a/8747795/1127492

BTW, 2 meters is pretty challenging. For more information on accuracy see here: http://www.gps.gov/systems/gps/performance/accuracy/#difference

Community
  • 1
  • 1
Stefan
  • 4,645
  • 1
  • 19
  • 35