2011-09-06 34 views
0

我在地图上两点:MapView上的多层Overlay对象。可能吗?

  1. 用户的位置(这被重绘每次收到新坐标时间)
  2. 拣选位置,其用户可以选择下摆自我(用胶带在地图上)。如果选择新点,则立即删除旧点。

问题:

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

问:

将它无论如何可以管理在MapView的叠加多层对象?

回答

1

您可以使用Overlay创建Multiple子类。现在当前的位置是固定的,我认为你不能做任何像onclick或者其他只能显示和维护当前位置的类。

所以现在选择位置。好吧,我认为你想改变该针位置的位置。正如你可以在onTap中实现的那样,你可以使用onTouch()方法并实现地图的down,move,up事件,假设我点击地图,那么你现在就可以将这个位置值转换成屏幕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)); 
} 

这里用户水龙头是我的抽签方法,该方法是在绘制调用()方法

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