如何在HERE MAP中执行地图标记点击(android)

时间:2016-11-10 09:25:13

标签: android here-api

我正在使用地图。我发现了一个问题。 我如何知道点击哪个标记?

@Override
public boolean onMapObjectsSelected(List<ViewObject> list) {..)

使用On Gesture Listener我得到了这个方法,但是如何找到特定的地图标记对象和地图标记标题等。

3 个答案:

答案 0 :(得分:6)

要获取点击的标记,请执行以下onMapObjectsSelected方法。

for (ViewObject viewObject : list) {
    if (viewObject.getBaseType() == ViewObject.Type.USER_OBJECT) {
        MapObject mapObject = (MapObject) viewObject;

        if (mapObject.getType() == MapObject.Type.MARKER) {

           MapMarker window_marker = ((MapMarker) mapObject);

           System.out.println("Title is................."+window_marker.getTitle());

              return false;
            }
        }
   }

你必须找出在循环中选择了哪种对象类型。

答案 1 :(得分:0)

  MapGesture.OnGestureListener onGestureListenernew= new 
  MapGesture.OnGestureListener() {
    @Override
    public void onPanStart() {

    }

    @Override
    public void onPanEnd() {

    }

    @Override
    public void onMultiFingerManipulationStart() {

    }

    @Override
    public void onMultiFingerManipulationEnd() {

    }

    @Override
    public boolean onMapObjectsSelected(List<ViewObject> list) {

        for (ViewObject viewObject : list) {
            if (viewObject.getBaseType() == ViewObject.Type.USER_OBJECT) {
                MapObject mapObject = (MapObject) viewObject;

                if (mapObject.getType() == MapObject.Type.MARKER) {

                    MapMarker window_marker = ((MapMarker)mapObject);
                     Log.d("danish","danish");
                    System.out.println("Title is................."+window_marker.getInfoBubbleHashCode());
                    Toast.makeText(m_activity,"Hello"+window_marker.getCoordinate(),Toast.LENGTH_LONG).show();
                    return false;
                }
            }
        }
        return false;
    }

    @Override
    public boolean onTapEvent(PointF pointF) {

        return false;
    }

    @Override
    public boolean onDoubleTapEvent(PointF pointF) {
        return false;
    }

    @Override
    public void onPinchLocked() {

    }

    @Override
    public boolean onPinchZoomEvent(float v, PointF pointF) {
        return false;
    }

    @Override
    public void onRotateLocked() {

    }

    @Override
    public boolean onRotateEvent(float v) {
        return false;
    }

    @Override
    public boolean onTiltEvent(float v) {
        return false;
    }

    @Override
    public boolean onLongPressEvent(PointF pointF) {
        return false;
    }

    @Override
    public void onLongPressRelease() {

    }

    @Override
    public boolean onTwoFingerTapEvent(PointF pointF) {
        return false;
    }
};

然后添加

m_mapFragment.getMapGesture().addOnGestureListener(onGestureListenernew);

答案 2 :(得分:0)

@Override
public boolean onMapObjectsSelected(List<ViewObject> list) {

    for (ViewObject viewObject : list) {
        if (viewObject.getBaseType() == ViewObject.Type.USER_OBJECT) {
            MapObject mapObject = (MapObject) viewObject;

            if (mapObject.getType() == MapObject.Type.MARKER) {

                MapMarker window_marker = ((MapMarker)mapObject);
                Log.d("Title->",window_marker.getTitle());
                Log.d("description->",window_marker.getDescription());
               return true;
            }
        }
    }
    return false;
}