-2
我目前正在研究一个简单的健身应用程序,允许用户跟踪他/她的表现(跑步,走路)。我一直在使用位置管理器来获得非常好的移动速度。但是我需要获得距离,如何使用位置管理器(长和纬)来获得距离?使用位置管理器计算行动距离的机器人
感谢
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_track);
start = (Button) findViewById(R.id.btnStart);
speed = (TextView) findViewById(R.id.txtSpeed);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
//initialize location listener
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
getSpeed(location);
double lat2 = location.getLatitude();
double lng2 = location.getLongitude();
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
//get the speed from the given location updates
public void getSpeed(Location location) {
currentSpeed = (location.getSpeed() * 3600/1000);
String convertedSpeed = String.format("%.2f", currentSpeed);
speed.setText(convertedSpeed + "Km/h");
}
};
不要转发问题! – Selvin