我正在写一个代码,它给了我纬度,经度和地址。但经度和经度在小数点后只显示7个位置,我希望它更准确,即。小数点后最多15个数字请帮忙谢谢 以下是我的代码,我正在通过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)
{
}
}
答案 0 :(得分:5)
但经度和经度在小数点后仅显示7个位置
在赤道,纬度和经度均为~111公里。纬度在靠近极点时更小。
小数点后7位~111 / 10000000公里= ~0.0000111公里= ~0.0111米= ~1.11厘米。
即使达到这个水平,GPS也不准确,更不用说15个地方了。