开发者

Drag marker on map

开发者 https://www.devze.com 2023-01-19 22:54 出处:网络
How can I drag a marker on the map? How to handle it in onTouchEvent()? I had written one code that actually drags. But it feels like the map is moving instead of the marker. That code is written bel

How can I drag a marker on the map? How to handle it in onTouchEvent()?

I had written one code that actually drags. But it feels like the map is moving instead of the marker. That code is written below:

public boolean onTouchEvent(MotionEvent event, MapView mapView) {

   /*Action to be taken on ACTION_UP(value=1) and ACTION_DOWN(value=0)*/
   if(event.getAction() == 0 || event.getAction() == 1){
      mapView.displayZoomControls(true);
   }  

   /*Action to be taken on ACTION_MOVE(value=2)*/
   if(event.getAction() == 2){  
      for(int i = 0; i < mOverlays.size() ; i++){
        mOverlays.remove(i);
      }

      GeoPoint point = mapView.getProjection().fromPixels((int) event.getX(),(int) 
                  event.getY());

      OverlayItem overlayItem = new OverlayItem(point, "", "");
      addOverlay(overlayItem); 
      mapView.getController开发者_StackOverflow().setCenter(point);
   }

   return true;
}

Is there any solution for this?


Of course the map is moving. You are telling the map to move via setCenter().

Here is a sample project showing drag and drop of OverlayItems.

0

精彩评论

暂无评论...
验证码 换一张
取 消