Question

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_;

        }
Was it helpful?

Solution

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.

OTHER TIPS

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")
 }

Swift 4+

Adopt GMSMapViewDelegate and use this protocol

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
           print("marker tapped:", marker)
           return true
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top