如何在Google Maps API V2中从当前位置到纬度/经度目的地获取英里/公里和负值。如果我得到此值,我想存储在textview中。
我的代码是:
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class DetailMapActivity extends SherlockActivity {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_detail_map);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
map.setMyLocationEnabled(true);
LatLng LOC_DESTINATION = new LatLng(-6.33438, 106.74316);
map.addMarker(new MarkerOptions().position(LOC_DESTINATION)
.title("Destination Title").snippet("Destination Description"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(LOC_DESTINATION, 40));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
String miles = "what this code?";
Log.d("HaichalMap", miles);
}
}
感谢您的回答。
最佳答案
使用Location
类尝试一下
Location locationA = new Location("Location A");
locationA.setLatitude(lat_a);
locationA.setLongitude(lon_a);
Location locationB = new Location("Location B");
locationB.setLatitude(lat_b);
locationB.setLongitude(lon_b);
int metres = Math.round(locationA.distanceTo(locationB)); // Returns in Metres
将仪表转换成所需的输出