Shashi Bhushan
Shashi Bhushan

Reputation: 1350

How to deselect a marker using HERE map android SDK

I have registered onMapObjectsSelected event to know which marker is clicked. 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.

Upvotes: 0

Views: 315

Answers (1)

AndrewJC
AndrewJC

Reputation: 1478

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. If so, multiple objects could be returned by the 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. 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 ViewObjects using GeoCoordinate#distanceTo(GeoCoordinate coord). Alternatively, you can try using the PointF from onTapEvent(PointF p) to call Map#getSelectedObjects(PointF p) directly. Although this will not have a margin of error around the touchpoint so the touch interaction may not be as pleasant.

Upvotes: 1

Related Questions