0

在 iOS 中触摸或点击标记时如何制作地图气球?简而言之,我希望我的应用程序的地图功能能够弹出一个地图气球,以显示有关标记所在位置的某些信息。

我正在使用谷歌地图,因为我听说现在它比 iOS 中的 Mapkit 更准确。

下图是我在这个问题中的目标:

触摸覆盖时

4

2 回答 2

4

如果您想要此自定义地图气球作为标记,在使用 google maps sdk for ios 时,您可以使用该功能

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

这允许您为标记显示自定义信息窗口,而不是默认信息窗口。您需要设计一个如图所示的视图,分配所需的值并在此函数中返回视图。请查看此较早的帖子以查看制作自定义信息窗口的示例。您可以通过设置属性值来调整信息窗口相对于标记的位置marker.infoWindowAnchor

于 2013-07-26T19:38:04.777 回答
1

要创建类似注解的气球,您需要覆盖MKMapView's方法

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

像这样:

- (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;
        }

要创建在您点击注释时打开的自定义弹出框/视图,您需要覆盖 MKMapViewDelegate 的方法

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

在此方法中,您需要创建一个 Popover 控制器并呈现它。

于 2013-07-23T08:11:57.730 回答