简体   繁体   中英

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:

当覆盖层被触摸时

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM