3
votes

I am new to ios and I'm not sure how I could update a google maps custom marker info window image after my http post request is complete.

My current custom marker info window xib looks like this

Custom Marker Info Window

In my delegate method mapView(mapView: GMSMapView, markerInfoWindow marker: GMSMarker) I made an Alamofire.request which fetches my image for me. I want the user to be able to immediately to see the info window without waiting for the image to be complete. The request is as follows

Alamofire.request(.POST, appDelegate.host + "/get-img", parameters: params as? [String : AnyObject], encoding: .JSON , headers: headers)
    .response{ (request, response, data, error) in
        if let img = data {
            infoWindow.img.image = UIImage(data: img)
        }
    }

however the image in the info window does not update at all. I understand that google maps api stated that the view may not update after returning the view in the delegate method but are there any other workarounds?

I have also considered requesting for all images relating to all markers on the map before the map view is loaded but that may just be too expensive.

1

1 Answers

3
votes

I solved a similar problem by setting:

marker.tracksInfoWindowChanges = true

in the mapView markerInfoWindow method (before requesting the image) and then after image is loaded (i.e. in the "response" handler), I set the image in the infoWindow and then set the flag back, so it doesn't consume resources (see tracksInfoWindowChanges docs):

marker.tracksInfoWindowChanges = false