Reputation: 3
I am building an app which can detect location change by reading GPS data. I am observing the change on longitude and latitude to detect the location change. But my app is only working when I go far away. The value I get on latitude and longitude is only upto two decimal points.Is there any way to get more precise data of latitude and longitude in android? I want get the value upto 7 or 8 decimal point. My code is given below-
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.d("GPS ", "ON");
mysample = mysample + "GPS = 1 \n";
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double latitude = 0;
double longitude = 0;
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
if ( plat != latitude || plong != longitude) {
Log.d("GPS MOVING ", "ON");
mysample = mysample + "GPS MOVING = 1 \n";
Log.d("GPS CORDINATE ", "" + longitude + "" + latitude);
plat = latitude;
plong = longitude;
} else {
Log.d("GPS MOVING ", "OFF");
mysample = mysample + "GPS MOVING = 0 \n";
Log.d("GPS CORDINATE ", "" + longitude + "" + latitude);
}
} else {
Log.d("GPS ", "OFF");
mysample = mysample + "GPS = 0 \n";
Log.d("GPS MOVING ", "OFF");
mysample = mysample + "GPS MOVING = 0 \n";
}
Upvotes: 0
Views: 78
Reputation: 8082
Getting precise data of latitude and longitude is a nice idea however, setting location results to 7 or 8 decimal points is practically used in surveying purposes, as shown in Decimal degrees in Wikipedia.
A perfect explanation for this concern can be found in this thread.
Also, please check solution given in this SO post - How to better handle GPS location and android. Hope it helps!
Upvotes: 1