0

I am putting markers on a mapView. The markers are showing objects from a NSArray populated from JSON. Now, if the user taps on a marker, it opens an info window which shows text from two fields (keys) from the array. What I need is to put a button inside the info windows. If the user taps on the button, a detail viewController including more information about the selected object must be opened.

This is the code that puts the markers on the mapView:

for ( int i=0;i<[categorias count];i++){


            GMSMarker *marker = [[GMSMarker alloc] init];

            double latitud = [[[categorias objectAtIndex:i] objectForKey:@"latitudEmpresa"] doubleValue];

            double longitud = [[[categorias objectAtIndex:i] objectForKey:@"longitudEmpresa"]doubleValue];

            marker.position = CLLocationCoordinate2DMake(latitud, longitud);

            NSString *nombre = [[categorias objectAtIndex:i] objectForKey:@"nombreEmpresa"];
            marker.title = nombre;

            NSString *direccion = [[categorias objectAtIndex:i] objectForKey:@"direccionEmpresa"];
            marker.snippet = direccion;

            marker.map = mapView_;

        }
mvasco
  • 4,965
  • 7
  • 59
  • 120

3 Answers3

1

According to the google map sdk documentation they add renderd image to the mapview when user tap to the marker. So normaly not possible to add button to as adding uiview. But it will triger event called "didTapWindowOfMarker".

You can find more information here.

Community
  • 1
  • 1
Hasintha Janka
  • 1,608
  • 1
  • 14
  • 27
  • 1
    Thank you, i have included following code, but it is never called: -(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker{ NSLog(@"MARKER..... %@",marker); } – mvasco Feb 27 '14 at 06:55
  • It called when you tap in annotation view. Did you try it. Don't forget set delegates. http://stackoverflow.com/questions/15125158/mapview-didtapinfowindowofmarker-method-does-not-work-google-maps-ios-sdk – Hasintha Janka Feb 27 '14 at 06:59
0

The accepted answer is correct, I just wanted to add the equivalent solution in Swift

 func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker)
 {
        // An Info window is rendered as an image, it will not respond to actions.
        print("Info Window Clicked On")
 }
Fiach Reid
  • 6,149
  • 2
  • 30
  • 34
0

Swift 4+

Adopt GMSMapViewDelegate and use this protocol

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
           print("marker tapped:", marker)
           return true
    }
dbrownjave
  • 437
  • 1
  • 8
  • 19