user255936
user255936

Reputation: 23

Android: Bing Maps API - how to handle Pushpin click?

I have

MapView map = new MapView(this, MapRenderMode.VECTOR); 
MapIcon pushpin = new MapIcon();
MapElementLayer mPinLayer = new MapElementLayer();

mPinLayer.getElements().add(pushpin);
map.getLayers().add(mPinLayer);

and I need to execute this:

Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {});

but in Android Java, not JS

Upvotes: 1

Views: 279

Answers (1)

user255936
user255936

Reputation: 23

Found workaround.

mMapView.addOnMapTappedListener(new OnMapTappedListener() {
        @Override
        public boolean onMapTapped(MapTappedEventArgs mapTappedEventArgs) {
            Point position = mapTappedEventArgs.position;
            LinkedList<MapElement> elements = mMapView.findMapElementsAtOffset(position);

            for (MapElement mapElement: elements)
            {
                if (mapElement instanceof MapIcon) {
                    MapIcon mapIcon = (MapIcon) mapElement;
                     // Do your thing. For example set fly out visibility.
                     // mapIcon.setIsFlyoutVisible(!mapIcon.getIsFlyoutVisible());
                }
            }

            return false;
        }
    });

Upvotes: 1

Related Questions