Android的折线 - 添加逐点 [英] Android Polyline - Adding point by point

查看:107
本文介绍了Android的折线 - 添加逐点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个地图,并且每个10米我用LocationListener的刷新我的位置,并获得新的经度和纬度。现在,我希望用户走的路线会以红色线条显示。所以每次的OnLocationChange()从LocationListener的类叫做,我想更新的最后一个位置和新位置之间的线路地图。

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);
}

在OnLocationChanged我称之为:

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.

感谢

推荐答案

首先翻译位置经纬度

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);

这篇关于Android的折线 - 添加逐点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆