0

我在地图上有两点:

  1. 用户位置(每次收到新坐标时都会重绘)
  2. 用户可以自己选择下摆的可选位置(通过在地图上点击)。如果选择了新点,则立即删除旧点。

问题:

当用户选择一个位置时Overlay.onTap(GeoPoint p, MapView mapView)被激活。MapView.getOverlays() 接收地图上的所有项目。我需要删除地图上的旧标记,但是无法区分哪个叠加对象是旧用户选择的位置,哪个是用户当前位置图标。

问题:

是否可以在 MapView 上管理多层叠加对象?

4

1 回答 1

1

您可以通过实现 Overlay 创建 Multiple 子类。现在当前位置是固定的,我认为你不能做任何事件,比如 onclick 等。 1 只显示和维护当前位置的类。

所以现在选择位置。好的,我认为您想更改该引脚的位置。正如您可以 onTap 实现的那样,您可以使用 onTouch() 方法并实现地图的向下、移动、向上事件假设如果我点击地图然后您获得该位置,现在将此位置值转换为屏幕 x,y将值添加到引脚以放置在该位置。

在这里我有这样的实现方式,当用户点击地图时将图钉放在地图上

public boolean onTouchEvent(MotionEvent event, final MapView mapView) {
    final int action=event.getAction();
    final int x=(int)event.getX();
    final int y=(int)event.getY();
    result = false;
    if (action==MotionEvent.ACTION_DOWN) {
        downPressed = true;
        drag = false;
        result = false;
    }else if (action==MotionEvent.ACTION_MOVE) {
        downPressed = false;
        drag=true;
    }else if (action==MotionEvent.ACTION_UP) {
        if(downPressed){
                if(task.equals(SINGLE_LOCATION) | isDirectionPoint | mapView.isStreetView()){
                    tempPoint = mapView.getProjection().fromPixels(x, y);
                    mapView.invalidate();
                }
            }

            drag = false;
            downPressed = false;
    }
    return(result | super.onTouchEvent(event, mapView));
}

这是我在 draw() 方法中调用的 draw 方法

private void drawFreeMarker(Canvas canvas, MapView mapView, boolean shadow) {
        Point screenPts = new Point();
        mapView.getProjection().toPixels(tempPoint, screenPts);
        //---add the marker---
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bluepin_38);
        canvas.drawBitmap(bmp, screenPts.x-((xCurLocOffset/2)-1), screenPts.y-(yCurLocOffset-1), null);
    }
于 2011-09-06T14:26:59.927 回答