java - 如何使用谷歌地图实时保存轨迹

标签 java android

我的想法是创建一个 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/

相关文章:

java - 如何从.java代码创建安装安装程序?

java - 正则表达式:交替字符/连续数字

java - 如何修复 InstallException/ShellCommandUnresponsiveException?

java - 为 Java 7 任务编写代码的最佳方法需要先完成其他任务

java - 无法在 Java 应用程序中加载 JDBC 驱动程序类 [oracle.jdbc.driver.OracleDriver]

java - 为什么 SQLite 会报错?

android - 滑出式键盘手机上的固定方向 Activity 生命周期

android - 设置焦点 EditText android

android - 导航架构组件动画

android - 发现 SQLite 数据库泄漏