我正在嘗試計算我的地理位置點和跟蹤這兩者之間的折線的標記之間的距離,但問題是當我輸出結果並且它給了我一個滿足感時距離(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
你能提供兩個位置的實際座標和適當的距離結果嗎? –