作为我的GPS functionality
的基础HelloMap3D Nutiteq
(Thx Jaak)的例子我改编自显示current GPS position
这个例子的不同之处,所以,没有增长的黄色圆圈,但是修复蓝色半透明圆圈,center point
作为我当前的位置,除了更新之外工作正常。如果location
发生变化,它应该删除过去的位置
此更新发生在方法onLocationChanged
中的示例中
这是我的主要活动
中的代码protected void initGps(final MyLocationCircle locationCircle) {
final Projection proj = mapView.getLayers().getBaseLayer().getProjection();
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
locationCircle.setLocation(proj, location);
locationCircle.setVisible(true);
}
// Another Methods...
}
}
我已经像这样调整了MyLocationCircle
Class
public void update() {
//Draw center with a drawable
Bitmap bitmapPosition = BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_home);
PointStyle pointStyle = PointStyle.builder().setBitmap(bitmapPosition).setColor(Color.BLUE).build();
// Create/update Point
if ( point == null ) {
point = new Point(circlePos, null, pointStyle, null);
layer.add(point);
} else { // We just have to change the Position to actual Position
point.setMapPos(circlePos);
}
point.setVisible(visible);
// Build closed circle
circleVerts.clear();
for (float tsj = 0; tsj <= 360; tsj += 360 / NR_OF_CIRCLE_VERTS) {
MapPos mapPos = new MapPos(circleScale * Math.cos(tsj * Const.DEG_TO_RAD) + circlePos.x, circleScale * Math.sin(tsj * Const.DEG_TO_RAD) + circlePos.y);
circleVerts.add(mapPos);
}
// Create/update line
if (circle == null) {
LineStyle lineStyle = LineStyle.builder().setWidth(0.05f).setColor(Color.BLUE).build();
PolygonStyle polygonStyle = PolygonStyle.builder().setColor(Color.BLUE & 0x80FFFFFF).setLineStyle(lineStyle).build();//0xE0FFFF
circle = new Polygon(circleVerts, null, polygonStyle, circle_data);
layer.add(circle);
} else {
circle.setVertexList(circleVerts);
}
circle.setVisible(visible);
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public void setLocation(Projection proj, Location location) {
circlePos = proj.fromWgs84(location.getLongitude(), location.getLatitude());
projectionScale = (float) proj.getBounds().getWidth();
circleRadius = location.getAccuracy();
// Here is the most important modification
update();
}
因此,每次我们的位置更改都会调用onLocationChanged(Location location)
方法,并且会调用locationCircle.setLocation(location)
并且最后一次调用它,它将被称为update
。
问题是,我做错了什么?和我该如何解决?
提前谢谢。
答案 0 :(得分:2)
您可以在每次更新时创建并添加新圈子。您应该重用单个,只需使用setVertexList()更新顶点。特别是这一行应该在onLocationChanged循环之外,在initGPS的某个地方可能是:
circle = new Polygon(circleVerts, null, polygonStyle, circle_data);