我想计算我的位置与另一个位置之间的距离并写入 它以一段时间在TextView中显示。
我试过了:
private LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.d(TAG_LOG, "In onLocationChanged(...)");
if(!mLatLngGpxList.isEmpty()) {
Location loc = new Location("");
loc.setLatitude(mLatLngGpxList.get(0).getLatitude());
loc.setLongitude(mLatLngGpxList.get(0).getLongitude());
float distance = mCurrentLocation.distanceTo(loc)/1000;
distanceTextView.setText("Distance to Track: " + distance + " Km");
}
}
};
(我也有这个......)
final LocationRequest locationRequest = new LocationRequest();
locationRequest.setInterval(UPDATE_INTERVAL);
locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL);
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationClient.requestLocationUpdates(locationRequest, mLocationListener);
只有在重新启动应用程序而不是实时应用程序时,距离才会变长。
也许我应该使用处理程序?