我的主要活动中有这段代码,它将在文本视图中显示位置数据:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_live);
startactivity();
}
启动活动功能:
private void startactivity()
{
GPSTracker gps = new GPSTracker(Live.this);
if(gps.canGetLocation())
{
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is: \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}
else
{
gps.showSettingsAlert();
}
}
我创建了一个单独的类 GPSTracker.java 来查找位置。
canGetLocation() 是一个检查是否有可用提供程序的函数。getLatitude() 查找纬度,getLongitude() 查找经度。
这些函数有效,我得到了“纬度”和“经度”变量中的值。
GPSTracker 类中的 onLocationChanged(Location location) 目前为空。
我想计算通过这种方法行进的距离: 计算一段时间内行进距离的最佳方法是什么?
但是我对 old_location 和 new_location 变量的使用方式感到困惑。它是如何工作的,我如何用我当前的函数/类来实现它?