How to get click event of marker using MapBox SDK?

BSavaliya picture BSavaliya · Feb 11, 2015 · Viewed 7.5k times · Source

I am using MapBox SDK for offline map I have added multiple markers on map, how to get click event for markers. Is there any way to get click event of marker?

Answer

BSavaliya picture BSavaliya · May 18, 2015

I got the solution for marker click event in mapbox using a functionality provided by mapbox sdk called ItemizedIconOverlay.

I have done like following :

   public void placeGTMarker() {
        alMarkerGT = new ArrayList<Marker>();
        marker = new Marker("my Marker", "", latLng);
        marker.setMarker(activity.getResources()
                .getDrawable(R.drawable.map_pin));
        mv.addMarker(marker);
        alMarkerGT.add(marker);
        itemizedIconOverlayGT = new ItemizedIconOverlay(activity, alMarkerGT,
                new OnItemGestureListener<Marker>() {

                    @Override
                    public boolean onItemSingleTapUp(int index, Marker item) {
                        return false;
                    }

                    @Override
                    public boolean onItemLongPress(int index, Marker item) {
                        return false;
                    }
                });
        mv.addItemizedOverlay(itemizedIconOverlayGT);
    }

We can perform any event on onItemSingleTapUp for single click and for long click we can use onItemLongPress method.

I have used in my application and it works great