我需要使用gps计算当前位置与给定位置之间的时间和距离。
任何人请提出想法
final TextView speedView = (TextView) findViewById(R.id.speedtxt);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
if (location.hasSpeed()) {
float speed = location.getSpeed() * 3.6f;// km/h
speedView.setText(String.format("%.0f km/h", speed));
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
};
答案 0 :(得分:1)
位置具有distanceTo
方法,该方法返回此位置与给定位置之间的大致距离(以米为单位)。 E.g
float distance = gpsLocation.distanceTo(dstLocation);
答案 1 :(得分:0)
查看 Location.distanceBetween(double startLatitude,double startLongitude,double endLatitude,double endLongitude,float [] results)方法
http://developer.android.com/reference/android/location/Location.html
//finding the distance between destination and mylocation
Location.distanceBetween(startLatitude , startLongitude, endLatitude , endLongitude , results);
// to convert metre to KM
if(results[0]>1000)
{
distString = (double)Math.round(results[0]/1000)+"km";
}
else
{
distString = Math.round(results[0])+"m";
}
Log.d("dist string",distString);
// Store the distances in array
distance[i]=distString;
而且只是chek,已经有问题了