我有一种在 Google map 上绘制路线的方法。
此方法需要 LatitudeLongitude
对象的 List
,顾名思义,该对象包含一对 double latitude
和 double 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/