I started working on an InfoWindowAdapter that is displaying location images inside the InfoWindow. I have a lot of different locations, therefore it is possible that an location image is not available on the phone and is downloaded from the web.
Now the Maps API states the following:
Note that a snapshot of the returned view will be taken and then rendered on the map so subsequent changes to the view will not be reflected by the info window on the map. To update the info window (e.g., after an image has loaded), just call showInfoWindow() and the view will be updated.
As I understand this I need to keep track of the marker that created the info window that I want to updated and call showInfoWindow once the image is loaded. I have an ImageDownloadService that will take a Handler that is notified if an image is finished loading.
If an image takes a little longer loading it is possible that the user opened another InfoWindow or closed the current Window scrolled away. The problem is that at the time I call showInfoWindow on the marker again to update the view I can not be sure that the InfoWindow is still displayed.
Is there a way to update the InfoWindow only if it is still displayed?
I've just been having a similar problem with
AsyncTask
s downloading and updating anInfoWindow
and after much banging my head against the wall this morning I've come up with this little workaround that should hopefully service your needs until Google sort this one out.I was calling
marker.showInfoWindow()
in theOnPostExecute()
method of myAsyncTask
, which re-called theInfoWindowAdapter
methods, which was ending up in a loop and never propagating my changes correctly.The solution I used was to store the currently selected marker and the
InfoWindow
View I wanted displayed. I've chucked in an example below where theTextView
is being updated on theDownloadBubbleInfo
AsyncTask
(similar to your image thread I believe).And the relevant lines from the
DownloadBubbleInfo
AsyncTask
:Now, all of this should make sure the correct marker is being populated with the correct information returned from your
AsyncTask
and hey presto another corner of the extremely awkward GoogleMaps v2 for Android API successfully circumnavigated!Might Marker's boolean isInfoWindowShown() method be what you are looking for?
Marker#isInfoWindowShown() - Google Maps Android API v2 documentation
It can't help when the InfoWindow was scrolled away from, though, for that, I think, you'll probably have to convert Marker's LatLng coordinates to screen coordinates or use this to check whether the marker is still on screen:
How to get Latitude/Longitude span in Google Map V2 for Android
I'm not sure whether it's possible at all to check if the window itself is still in map view bounds or not.