Search code examples
iosgoogle-mapsgoogle-maps-sdk-ios

Google Maps Custom InfoWindow Multiple Markers


I've implemented a custom Google Maps Marker InfoWindow into my project, however, I do not know how to pass extra data to custom InfoWindow when adding multiple markers on the map. I created a global variable that is updated before each marker is added but this isn't working.

Here is my code so far:

...
NSString *markerDesc;
NSString *markerTimeLeft;
NSString *markerDistance;
...

- (UIView *) mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
  CustomInfoWindow *infoWind = [[[NSBundle mainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];

  infoWind.lblTitle.text = marker.title;
  infoWind.imgCategory.image = marker.icon;
  infoWind.lblTimeLeft.text = markerTimeLeft;
  infoWind.lblDistance.text = markerDistance;
  infoWind.txtDescription.text = markerDesc;

  return infoWind;
}

The title and icon show up fine. The others (markerTimeLeft, markerDistance, markerDesc) show up but show the same data for each marker. I feel this happens because the markerInfoWindow delegate is only called once and therefore loads those variables only once. Any direction is greatly appreciated.


Solution

  • As a work around, I set the marker.title and marker.snippet fields with the extra data that I needed. I separated the small segments of data with a separator symbol of my choice and then parsed the string to populate the additional fields I needed. This was sufficient to solve the issue I was facing.