为了响应touch事件,需要设置OnMapTouchListener

示例:

private void initMapEventsListener()
{
       mapWidget.setOnMapTouchListener(new OnMapTouchListener() {    
           public void onTouch(MapWidget map, MapTouchedEvent event) {
               
               List objectTouchEvents = event.getTouchedObjectIds();

               // X coordinate of the touch in original image coordinates
               int mapX = event.getMapX();  

   // Y coordinate of the touch in original image coordinates

   int mapY = event.getMapY();

   // X coordinate of the touch in screen coordinates                 

   int screenX = event.getScreenX();

   // Y coordinate of the touch in screen coordinates
               int screenY = event.getScreenY();
               
               if (objectTouchEvents.size() == 1) {
                   ObjectTouchEvent objectTouchEvent = objectTouchEvents.get(0);
                   // Id of the layer that the map object belongs to
                   long layerId = objectTouchEvent.getLayerId();
                   // Id of the map object that was touched.

                   Object objectId = objectTouchEvent.getObjectId();                     
                   Toast.makeText(BrowseMapDemoActivity.this, "Touched object " + objectId + " on layer" + layerId + ", x: " + mapX + " y: " + mapY, Toast.LENGTH_SHORT).show();
               }
           }
       });
   }

 

posted on 2015-08-14 15:21  Joanna.Yan  阅读(728)  评论(0编辑  收藏  举报