Reputation: 460
I am writing a code which gives me latitude , longitude and adress. But latitude and longitude are showing upto only 7 places after decimal point and i want it to be more accurate ie. upto 15 numbers after decimal points please help and thank you following is my code where i am taking value by getLatitude & getLongitude
final String location = locationText.getText().toString();
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "dfdsfsd"+response, Toast.LENGTH_SHORT).show();
Log.i("My success",""+response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "my error :"+error, Toast.LENGTH_LONG).show();
Log.i("My error",""+error);
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map = new HashMap<String, String>();
map.put("locationText",location );
return map;
}
};
queue.add(request);
}
});
if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, 101);
}
getLocationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getLocation();
}
});
}
private void launchCall() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(package_name, class_name));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
void getLocation() {
try {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 5, this);
}
catch(SecurityException e) {
e.printStackTrace();
}
}
@Override
public void onLocationChanged(Location location) {
locationText.setText("Latitude: " + location.getLatitude() + "\n Longitude: " + location.getLongitude());
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
locationText.setText(locationText.getText() + "\n"+addresses.get(0).getAddressLine(0)+", "+
addresses.get(0).getAddressLine(1)+", "+addresses.get(0).getAddressLine(2));
}catch(Exception e)
{
}
}
Upvotes: 0
Views: 1872
Reputation: 1006664
But latitude and longitude are showing upto only 7 places after decimal point
At the equator, a degree of latitude and a degree of longitude are each ~111 kilometers. Degrees of latitude are smaller closer to the poles.
7 decimal places is ~111/10000000 kilometers = ~0.0000111 kilometers = ~0.0111 meters = ~1.11 centimeters.
GPS is not accurate to even that level, let alone 15 places.
Upvotes: 5