【发布时间】:2017-01-18 22:49:02
【问题描述】:
我目前正在开发一个简单的健身应用程序,该应用程序允许用户跟踪他/她的表现(跑步、步行)。我一直在使用位置管理器来获得非常好的移动速度。但是我需要获取行驶距离,如何使用位置管理器(经纬度)来获取距离?
谢谢
@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");
}
};
【问题讨论】:
-
请勿转发问题!
标签: android