Muju Muju -4 years ago 87
iOS Question

How to add action on the title of Google Maps maker in Objective C

I am new in iOS and I am facing problem regarding to add action to the title of Google Maps

I am using code like this

for (int i=0; i<NameHSArray.count; i++) {
double LatitudeDouble = [LatitudeHSArray[i] doubleValue];
double LongitudeDouble = [LongitudeHSArray[i] doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(LatitudeDouble, LongitudeDouble);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = NameHSArray[i];

if([TypeHSArray[i] isEqualToString:@"ESIC"])
{
marker.icon = [UIImage imageNamed:@"mapicon2.png"];
}
else
{
marker.icon = [UIImage imageNamed:@"mapicon1.png"];
}

GMSCameraUpdate *zoomCamera = [GMSCameraUpdate zoomIn];
[mapView animateWithCameraUpdate:zoomCamera];

marker.map = mapView;
}


As in the Image

enter image description here

How to add the action when I click on Nobel Hospital.

Answer Source

Implement the GMSMapViewDelegate method

- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
    // your click action
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download