Skip to content Skip to sidebar Skip to footer

Show Dynamically To Infowindow Googlemap V2

I'm developing a travel app. On Google map API V2 feature, I want each InfoWindow have an different image. I've override WindowInfoAdapter for custom title and detail text. publi

Solution 1:

You would have to create additional data structure to hold your images, e.g.:

Map<Marker, Drawable> allMarkersMap = newHashMap<Marker, Drawable>();

after you add marker to GoogleMap:

allMarkersMap.put(marker, iImages);

in getInfoContents:

Drawable iImages = allMarkersMap.get(marker);

and add it to the ImageView.

Another way would be to use Android Maps Extensions, which has methods like Marker.setData(Object) and Object Marker.getData(). This you can use to directly assign Drawable to marker, just like you do with snippet.

Solution 2:

After three hours of scratching my head I solved this with postDelayed handler. The idea is: object, comtaining data for infoWindow, must have some Drawable field (image, for example). When you first time show infoWindow, some AsyncTash or another async process obtains picture and put it's deawable into image. You must set postDealyed runnable, which will check image value everu X millis and if it became not null, re-show infoWindow, else - set another postDelayed run. My part of getInfoContents code:

final One o=data.get(id);
  View v=o.inflateMarkerInfo(this);
  if (o.image==null) {
    final Handler h=new Handler();
    h.postDelayed(new Runnable() {
      @Overridepublic void run() {
        if (o.image!=null) m.showInfoWindow();
        else h.postDelayed(this, 100);
      }
    }, 100);
  }
  return v;

Sure, you can return null on first call so your infoWindow will not show until image obtained, but it will cause some lag.

Post a Comment for "Show Dynamically To Infowindow Googlemap V2"