简体   繁体   English

如何使用HERE Map Android SDK取消选择标记

[英]How to deselect a marker using HERE map android SDK

I have registered onMapObjectsSelected event to know which marker is clicked. 我已经注册了onMapObjectsSelected事件,以了解单击了哪个标记。 While debugging, i found that it returns all markers which are previously selected along with marker clicked by user. 在调试时,我发现它会返回以前选择的所有标记以及用户单击的标记。

@Override
public boolean onMapObjectsSelected(List<ViewObject> objects) {
    // objects list holds all markers which are clicked.
    for (ViewObject viewObj : objects) {
        if (viewObj.getBaseType() == ViewObject.Type.USER_OBJECT) {
            if (((MapObject) viewObj).getType() == MapObject.Type.MARKER) {
                MapMarker selectedMarker = ((MapMarker) viewObj);
            }
        }
    }
}

But I need to identify which one is clicked recently from list. 但是我需要确定最近从列表中单击了哪个。 So is there any way to do this OR HERE map SDK provides any functionality to deselect marker out of the box. 因此,有什么方法可以执行此操作,或者在此处Map SDK提供了取消选中标记的任何功能。

Are the Markers close enough to each other that they may be all selected by the same tap gesture? 标记是否彼此足够靠近,以致可以通过相同的轻击手势将它们全部选中? The tap gesture uses a small bounding box to check for selected objects using the Map#getSelectedObjects(ViewRect rect) API. 轻击手势使用一个小的边界框来使用Map#getSelectedObjects(ViewRect rect)API检查选定的对象。 If so, multiple objects could be returned by the API. 如果是这样,API可以返回多个对象。 It should not save the state of previously selected objects as you are describing, so possibly the objects are so close together they are all being selected. 它不应该像您所描述的那样保存先前选择的对象的状态,因此可能这些对象之间距离太近,以致所有对象都被选中。

If this is the case, the first item in the returned List<ViewObject> should be the best match. 如果是这种情况,则返回的List<ViewObject>的第一项应该是最佳匹配。 If it doesn't seem to be you can try sorting by distance from the actual touch point by using Map#pixelToGeo(PointF point) and comparing the distance of the touch point and the ViewObject s using GeoCoordinate#distanceTo(GeoCoordinate coord) . 如果不是这样,则可以尝试使用与实际触摸点的距离排序,方法是使用Map#pixelToGeo(PointF point)然后使用GeoCoordinate#distanceTo(GeoCoordinate coord)比较触摸点和ViewObjectGeoCoordinate#distanceTo(GeoCoordinate coord) Alternatively, you can try using the PointF from onTapEvent(PointF p) to call Map#getSelectedObjects(PointF p) directly. 或者,你可以尝试使用PointFonTapEvent(PointF p)来调用Map#getSelectedObjects(PointF p)直接。 Although this will not have a margin of error around the touchpoint so the touch interaction may not be as pleasant. 尽管这在接触点周围不会有误差余量,所以触摸交互可能不会那么令人愉快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM