Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I'm returning a UIImageView in - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker;

This UIImageView loads images dynamically through a URL using SDWebImage.

As the documentation says about marker info windows:

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.

The point is that after downloading the image the info window doesn't refresh and keep showing the placeholder image until user hides then show it back again..

So I need to force refresh the contents of the markerInfoWindow in the block of image downloaded..

like image 313
Shady Elyaski Avatar asked Jun 27 '13 11:06

Shady Elyaski


2 Answers

In GoogleMaps iOS SDK 1.13.0 and above, they have added this functionality. To enable this, simply set the tracksInfoWindowChanges property on GMSMarker to YES.

Example:

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {     marker.tracksInfoWindowChanges = YES;      MyInfoWindow *infoWindow = [[MyInfoWindow alloc] init];     [infoWindow.imageView sd_setImageWithURL:imageUrl];     return infoWindow; } 

Source:

  • https://code.google.com/p/gmaps-api-issues/issues/detail?id=5559
  • https://developers.google.com/maps/documentation/ios-sdk/releases#version_1131_-_may_02_2016
like image 169
Enrico Susatyo Avatar answered Oct 09 '22 11:10

Enrico Susatyo


This is how I fixed the problem using the workaround bellow:

UIImage *img = [[SDWebImageManager sharedManager] imageWithURL:[NSURL URLWithString:Img_URL]]; //Img_URL is NSString of your image URL     if (img) {       //If image is previously downloaded set it and we're done.         [imageView setImage:img];     }else{         [imageView setImageWithURL:[NSURL URLWithString:Img_URL] placeholderImage:[UIImage imageNamed:@"defaultPin"] success:^(UIImage *image, BOOL cached) {             if (!marker.snippet || !cached) {                 [marker setSnippet:@""];                 //Set a flag to prevent an infinite loop                 if (mapView.selectedMarker == marker) {  //Only set if the selected marker equals to the downloaded marker                     [mpVu setSelectedMarker:marker];                 }             }         } failure:^(NSError *error) {          }];     } 
like image 38
Shady Elyaski Avatar answered Oct 09 '22 10:10

Shady Elyaski