2

According to the document from Google, the info window was rendered before I get the image.

Note: The info window is rendered as an image each time it is displayed on the map. 
This means that any changes to its properties while it is active will not be immediately visible.     
The contents of the info window will be refreshed the next time that it is displayed.

Are there anyone is using AFNetworking's image cache and successfully update the infowindow view without polluted the marker's snippet? I've searched but I couldn't find any solution for my scenario. I have address and some other information in the marker's snippet, so I can't use it as a flag.

BTW, I'm following this tutorial from Google to create the info window from xib

Refs:

How to force refresh contents of the markerInfoWindow in Google Maps iOS SDK

iOS: Dynamic Marker Info Window

https://developers.google.com/maps/documentation/ios/marker#info_windows

Community
  • 1
  • 1
Ryan Wu
  • 5,963
  • 2
  • 36
  • 47

2 Answers2

6

I solved a similar problem by setting:

marker.tracksInfoWindowChanges = true

in mapView markerInfoWindow and then after image is loaded (i.e. in "success:" completion handler, I set the image and then set:

marker.tracksInfoWindowChanges = false

Also see the offical docs for tracksInfoWindowChanges here.

zigah
  • 444
  • 3
  • 10
2

I solved the problem as following

I use this property as the info window.

@property (nonatomic) MyInfoWindow* infoWindow 

And this is how I wrote the delegate method of GMSMapViewDelegate

- (UIView*)mapView:(GMSMapView*)mapView markerInfoWindow:(GMSMarker*)marker
{
    //Prepare Data
    MyEvent* selectedEvent = [EventManager eventForEventID:marker.objectID];
    //Prepare Thumbnail URL
    NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[selectedEvent getSmallBannerWithSize:@"w50"]];

    //Prepare InfoView's UIView
    _infoWindow = [[[NSBundle mainBundle] loadNibNamed:@"infoWindowView" owner:self options:nil] objectAtIndex:0];
    _infoWindow.title.text = selectedEvent.eventName;

    //Get cached image from AFNetworking
    UIImage* img = [[UIImageView sharedImageCache] cachedImageForRequest:request];
    if (img == nil) {
        [_infoWindow.thumbnail setImageWithURLRequest:request 
                               placeholderImage:[UIImage imageNamed:@"placeholder"] 
          success:^(NSURLRequest* request, NSHTTPURLResponse* response, UIImage* image) {
            //Invoke selection to call this delegate method again
            [mapView setSelectedMarker:marker]; 
        } failure:^(NSURLRequest* request, NSHTTPURLResponse* response, NSError* error) {
            NSLog(@"RY fetching thumbnail image error : %@", request);
        }];
    } else {
        // If we can get the cached image, which means the image is downloaded, 
        // then update the info window
        _infoWindow.thumbnail.image = img;
    }
    return _infoWindow;
}
Ryan Wu
  • 5,963
  • 2
  • 36
  • 47