Android Polyline - Adding point by point

ぐ巨炮叔叔 提交于 2019-12-04 20:07:46

问题


I'm currently having a map, and each 10 meters I use LocationListener to refresh my location and get the new Latitude and Longitude. Now I wish that the route the user is taking will be displayed with a red line. So everytime the OnLocationChange() from LocationListener class is called, I want to update the map with a line between the last location and the new location.

So far I've added the following:

private void initializeDraw() {
    lineOptions = new PolylineOptions().width(5).color(Color.RED);
    lineRoute = workoutMap.addPolyline(lineOptions);
}

during the OnLocationChanged I call this:

drawTrail();

now what should I insert into this function so that each time it adds the newly attained location as a point and draws a line from the last to the new point.

Thanks


回答1:


First translate Location into LatLng:

LatLng newPoint = new LatLng(location.getLatitude(), location.getLongitude());

Then add a point to existing list of points:

List<LatLng> points = lineRoute.getPoints();
points.add(newPoint);
lineRoute.setPoints(points);


来源:https://stackoverflow.com/questions/17157454/android-polyline-adding-point-by-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!