【发布时间】:2013-07-09 21:23:04
【问题描述】:
我的主要活动中有这段代码,它将在文本视图中显示位置数据:
@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) 暂时为空。
我想通过这种方法计算行进的距离: What is the best way to calculate distance travelled over a period of time?
但我对 old_location 和 new_location 变量的使用方式感到困惑。 它是如何工作的?如何使用我当前的函数/类来实现它?
【问题讨论】: