Raphael Pineda
Raphael Pineda

Reputation: 420

Google maps for iOS [map balloons]

How do I make map balloons when a marker is being touched or tapped in iOS? to put it simply i want my application's map feature to be able to popup a map balloon to display certain information on the location where the marker is located.

I'm using google maps since i've heard that for now it is more accurate than the Mapkit in iOS.

the image below is my objective in this question:

when an overlay is touched

Upvotes: 0

Views: 1696

Answers (2)

tony m
tony m

Reputation: 4789

If you want this custom map balloons for your markers, while using google maps sdk for ios, you can use the function

- (UIView *) mapView:   (GMSMapView *)  mapView markerInfoWindow: (GMSMarker *) marker

This allows you to display a custom info window for a marker instead of the default infowindow. You need to design a view as shown in your picture , assign the required values and return the view in this function. Please check this earlier post to see an example of making a custom infowindow . You can adjust how the infowindow is located with respect to the marker, by setting value for the property marker.infoWindowAnchor

Upvotes: 4

Puneet Sharma
Puneet Sharma

Reputation: 9484

To create a balloon like annotation , you need to override MKMapView's method

- (MKAnnotationView *)viewForAnnotation:(id < MKAnnotation >)annotation

Like this:

- (MKAnnotationView *)viewForAnnotation:(id < MKAnnotation >)annotation{
    static NSString* annotationIdentifier = @"Identifier";
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    if(annotationView)
        return annotationView;
    else
    {
        MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
 // here we say NO to call out, it means the default popover type view wont open when you click on an        //annotation and you can override to show your custom popover 
        annotationView.canShowCallout = NO;
// here you need to give a ballon image
            annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:@"balloon.png"]];        
            return annotationView;
        }
        return nil;
        }

To create the custom popover/ view that opens when you tap on an annotation , you need to override MKMapViewDelegate's method

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

Here in this method you woould need to create a Popover Controller and present it.

Upvotes: 1

Related Questions