我正在尝试计算我的地理位置点和跟踪这两者之间的折线的标记之间的距离,但问题是当我输出结果并且它给了我一个满足感时距离(1.125405E7)代替(例如)1,250米。使用DistanceTo时出现的问题(距离不正确)
这是我的代码
//Gets the latitude & longitude of my Geolocation
Location location = new Location("A");
location.setLatitude(location.getLatitude());
location.setLongitude(location.getLongitude());
//Gets the location of a marker/Polyline which i put using onMapLongCliclistener
Location locationb = new Location("B");
locationb.setLatitude(latLng.latitude);
locationb.setLongitude(latLng.longitude);
//Calculates the distance between Geolocation/Marker
double distance=locationb.distanceTo(location);
String distancia = String.valueOf(distance);
Toast.makeText(MapsActivity.this,distancia,
Toast.LENGTH_SHORT).show();
任何提示或解决方案?
非常感谢!
要设置纬度'A'的经度两次,从未设置的纬度。这是你的真实代码还是错误? –
@MarkusKauppinen固定,仍然给我很大的距离 – QuickAccount123
你能提供两个位置的实际坐标和适当的距离结果吗? –