我的想法是创建一个 ArrayList
位置,每次我将位置数据保存在该列表中时,我都会在每两个点之间绘制一条折线。
我的问题是关于 Google map 方法 onLocationChanged()
。我想知道它是自动调用的,我的意思是每次位置改变时调用,还是当用户点击获取当前位置按钮时调用?
如果有人有更好的主意请告诉我?
最佳答案
基本上每次位置更改时都会调用 onLocationChanged。 然而,在其中实现您的代码是个坏主意,您可以做类似的事情
public class GPSTracker implements LocationListener{
private Location location ;
public Location getLocation(){
return this.location;
}
// .. code
@Override
public void onLocationChanged(Location location) {
this.location=location;
}
}
现在在您的主要 Activity 中,您可以通过制作 GPSTracker 的对象来获取位置 然后像这样
GPSTracker=new GPSTracker(this);
gpsTracker.getLocation (); //this will provide you with longitude,latitude then you can control it with a thread or something like that, by calling getLongitude,getLatitude you can get the location paramter
请注意,构造函数将上下文作为参数,因此将 Activity 的上下文传递给 GPSTracker 类 请检查以下 link
关于java - 如何使用谷歌地图实时保存轨迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46526145/