【问题标题】:Google Maps iOS SDK : access InfoWindow after creationGoogle Maps iOS SDK:创建后访问 InfoWindow
【发布时间】:2014-11-19 00:26:48
【问题描述】:

当我点击一个标记时,我想快速显示一个包含基本信息的信息窗口,然后调用一个网络服务来返回我到标记的距离/路径。
我必须调用网络服务,而不是直接调用 Google Maps SDK,因为路径已修改为到达某些点。

我试过那个代码:

- (void)fillInfoWindowForMarker:(GMSMarker *)marker {
    // get infos
    NSURL * url = [WSHelper.sharedHelper getPathURLForOrigin:origin destination:dest inGreenPath:greenPath];

    NSDictionary * result = [WSHelper.sharedHelper getPathAtUrl:url];

    GMSPath * path = [result valueForKey:@"path"];
    NSString * distance = [result valueForKey:@"distance"];

    dispatch_async(dispatch_get_main_queue(), ^{
        pathLine = [GMSPolyline polylineWithPath:path];
        pathLine.strokeWidth = 2;
        pathLine.strokeColor = UIColor.blackColor;
        pathLine.map = map;
        infoWindow.distanceLabel.text = @"something"
    });
}

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
    if (infoWindow) {
        pathLine.map = nil;
        infoWindow = nil;
        pathLine = nil;
    }

    InfoWindowView * view =  [[[NSBundle mainBundle] loadNibNamed:@"InfoWindowView" owner:self options:nil] objectAtIndex:0];

    view.distanceLabel.text = @"0 km";

    infoWindow = view;
    view.tag = 678;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        [self fillInfoWindowForMarker:marker];
    });

    return view;
}

其中infoWindow 是我的控制器的UIView 子类属性。

在地图上绘制了路径,但标签没有更新。我试图打印地图子视图,但里面没有InfoWindow
我怎么能做到这一点?

【问题讨论】:

    标签: objective-c google-maps-sdk-ios


    【解决方案1】:

    markerInfoWindow 返回的视图不用作真实视图。相反,SDK 会对其进行截图,然后绘制该截图。

    这里描述了一种解决方法来强制刷新信息窗口:

    How to force refresh contents of the markerInfoWindow in Google Maps iOS SDK

    因此,您可以获取数据,将其缓存在某处,然后强制刷新。由刷新触发的对markerInfoWindow 的新调用可以访问缓存的数据并返回更新后的视图。

    【讨论】:

    • 这似乎正是我想要的,谢谢。
    猜你喜欢
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 2016-10-31
    • 2019-04-23
    • 2017-11-05
    • 1970-01-01
    相关资源
    最近更新 更多