Question

In Android, I have a MapQuest MapView. The MapView has a DefaultItemizedOverlay with an OverlayItem that, when clicked, displays an AnnotationView. This is basically what MapQuest demonstrates in the overlays section of their Getting Started guide.

That works just fine but what a few people have noticed is that there is no way to close the annotation. The user can click on another OverlayItem to display its annotation instead, but there's no way to hide one without opening another. I could add a button to the annotation to close it but I would prefer to have it close when the user taps outside the annotation. Is there a convenient way to do so?

The overlay already has an OverlayTapListener that displays the annotation. I was looking at modifying its logic but I found that it only gets called when an overlay item is tapped, not when the user taps elsewhere. Short of overriding the overlay's onTouchEvent() method and replicating its logic with small changes, does anyone have any ideas on how to accomplish this?

Was it helpful?

Solution

I struggled a lot with the same issue, and finally I found a workaround!

myMapView.addMapViewEventListener(new MapView.MapViewEventListener() {
    @Override
    public void moveStart(MapView mapView) { }
    @Override
    public void move(MapView mapView) { }
    @Override
    public void moveEnd(MapView mapView) { }
    @Override
    public void touch(MapView mapView) {
        annotation.hide();
    }
    @Override
    public void longTouch(MapView mapView) { }
    @Override
    public void zoomStart(MapView mapView) { }
    @Override
    public void zoomEnd(MapView mapView) { }
    @Override
    public void mapLoaded(MapView mapView) { }
});

It basically closes the annotation if clicked anywhere but markers on the map.

Hope it helps someone else who struggles to use the free MapQuest API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top