android - 在Android中使用gps获取路线点列表的有效方法

标签 android google-maps gps android-maps android-location

我有一种在 Google map 上绘制路线的方法。 此方法需要 LatitudeLongitude 对象的 List,顾名思义,该对象包含一对 double latitudedouble longitude .

现在我需要实现一个填充路线点列表的方法,以这种方式:

方法

protected void startFillList(){
  //to do
}

开始获取坐标并在移动过程中将这些添加到列表中,

方法

protected List<LatitudeLongitude> stopFillList(){
  //to do
}

停止获取新坐标并返回结果列表

我该怎么做?

如果我使用一段时间连续调用(直到达到停止条件)

locationManager.getLastKnownLocation(provider);

为了填充列表,应用程序被残酷地挂起。

最佳答案

如果我理解正确你的问题,你可以试试这个方法:

private ArrayList<LatLng> CoordsList = new ArrayList<>();
private static boolean addCoords = false;


protected void startFillList(){
   addCoords = true;
}

protected ArrayList<LatLng> stopFillList(){
   addCoords = false;
   return CoordsList; 
}


@Override
public void onLocationChanged(Location location) {

    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    // Creating a LatLng object and add to list
    currentCoods = new LatLng(latitude, longitude);

    //check condition if add coordinates
    if(addCoords)
        CoordsList.add(currentCoods);

}

希望对您有所帮助!

关于android - 在Android中使用gps获取路线点列表的有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29182822/

相关文章:

android - 从 Play 商店更新我的应用程序后,如何在 Android 上保存 QSettings 文件的内容以使其可读?

android - 进度条在省电模式下消失(Android 5.x)?

Javascript Angular Google map 自动完成 Api 不起作用

javascript - 使用 webpack 时 Google map 无法访问回调函数

iphone - iOS显示取决于位置和时间的通知

android - Android 谷歌地图中的 onLocationChanged 捕获的点太多

android - 在 AndEngine 中从场景中删除对象

java - 访问 CordovaWebView 对象

iphone - MKMapView 框架在 MKMapType 声明中没有 relief google-map 类型,但它可以工作

java - 位置需要许可