目前使用的是随机生成的点来绘制拆线。
public void draw() {
Random random = new Random(100);
LatLng start= new LatLng(30.47523,114.385532);
List<LatLng> points = new ArrayList<LatLng>();
int i = 0;
while (i++ < 100) {
double lat = random.nextDouble() * 0.1;
double lng = random.nextDouble() * 0.1;
LatLng latLng = new LatLng(start.latitude+lat, start.longitude+lng);
points.add(latLng);
}
// aMap.moveCamera(CameraUpdateFactory.newLatLng(points.get(points.size()-1)));
Map map = new Map(aMap);
TrackPathUtils.addPath(map, new ArrayList<Polyline>(), points, Color.RED, false);
}
/**
* Add a path.
*
* @param map the map
* @param paths the existing paths
* @param points the path points
* @param color the path color
* @param append true to append to the last path
*/
public static void addPath(Map map, List<Polyline> paths,
List<LatLng> points, int color, boolean append) {
if (points.size() == 0) {
return;
}
if (append && paths.size() != 0) {
Polyline lastPolyline = paths.get(paths.size() - 1);
ArrayList<LatLng> pathPoints = new ArrayList<LatLng>();
pathPoints.addAll(lastPolyline.getPoints());
pathPoints.addAll(points);
lastPolyline.setPoints(pathPoints);
} else {
AMap aMap = map.getAMap();
// PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng(43.828, 87.621), new LatLng(45.808, 126.55)).width(10).color(Color.RED);
PolylineOptions polylineOptions = new PolylineOptions().addAll(points).width(5).color(color);
Polyline polyline = aMap.addPolyline(polylineOptions);
paths.add(polyline);
}
points.clear();
}
原文:http://my.oschina.net/qzzsunly/blog/401754