【问题标题】:Google maps for iOS [map balloons]适用于 iOS 的 Google 地图 [地图气球]
【发布时间】:2013-07-22 03:26:54
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios google-maps google-maps-markers google-maps-sdk-ios


    【解决方案1】:

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

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

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

    【讨论】:

    • 一个不错的答案。很有帮助
    【解决方案2】:

    要创建一个类似注解的气球,你需要重写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 控制器并呈现它。

    【讨论】:

    • 您将需要使用 Mapkit.framework 和 MKMapView。然后,您可以调用 google 服务器以获取路线、方向等,并在 MKMapView 上显示它们
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多