Search code examples
androidhere-api

How to show info wndow on marker in here map SDK 3.6


old version have method showInfoBubble() but deprecated in sdk 3.6 of here map, now how to show info on marker.

Here are the code.

MapMarker marker = new MapMarker();
            GeoCoordinate geoCoordinate = new GeoCoordinate(c.getLat(), c.getLng());
            marker.setCoordinate(geoCoordinate);
            marker.setTitle(c.getTicket());
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Name : " + (TextUtils.isEmpty(c.getName()) ? "N/A" : c.getName().trim()) + "\n");
            stringBuilder.append("Address : " + (TextUtils.isEmpty(c.getStreetAddress()) ? "N/A" : c.getStreetAddress().trim()) + "\n");
            stringBuilder.append("Telephone : " + (TextUtils.isEmpty(c.getTelephone()) ? "N/A" : c.getTelephone().trim()));
            marker.setDescription(stringBuilder.toString());

            mMap.addMapObject(marker);

MapOverlay mapOverlay = new MapOverlay(view, marker.getCoordinate());

             mMapOverlay.put(c.getId(), mapOverlay);

Solution

  • The infoBubble in the HEREMobileSDK was deprecated for quite a long time already. In the deprecation message it was suggested to switch over to MapOverlay: https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/mapping/MapOverlay.html

    So, what does this mean: Instead of showing a quite static/predefined infobubble from the HERE mSDK, you should use MapOverlay, that let you add complete View objects (Android Views) as an overlay to a pinned position on the map.

    In your case, you might want to listen for the marker click event, and if this happens, then you add a Android View that looks how you want it as a MapOverlay to the map. The Map overlay is constructed like this: MapOverlay (View view, GeoCoordinate coordinate) and will be pinned to that given position.

    Keep a reference to the MapOverlay, since you need to handle on your own when it should appear and disappear.