简体   繁体   English

如何使用AFnetworking图像缓存在iOS Google Maps中刷新标记信息窗口?

[英]How to refresh marker info window in iOS Google maps with AFnetworking Image cache?

According to the document from Google, the info window was rendered before I get the image. 根据Google提供的文档,信息窗口是在获取图像之前渲染的。

Note: The info window is rendered as an image each time it is displayed on the map. 
This means that any changes to its properties while it is active will not be immediately visible.     
The contents of the info window will be refreshed the next time that it is displayed.

Are there anyone is using AFNetworking's image cache and successfully update the infowindow view without polluted the marker's snippet? 是否有人在使用AFNetworking的图像缓存并成功更新了信息窗口视图,而没有污染标记的代码段? I've searched but I couldn't find any solution for my scenario. 我已经搜索过,但是找不到适合我的方案的解决方案。 I have address and some other information in the marker's snippet, so I can't use it as a flag. 我在标记的代码段中有地址和其他信息,因此不能将其用作标记。

BTW, I'm following this tutorial from Google to create the info window from xib 顺便说一句,我正在按照Google的本教程从xib创建信息窗口

Refs: 参考:

How to force refresh contents of the markerInfoWindow in Google Maps iOS SDK 如何在Google Maps iOS SDK中强制刷新markerInfoWindow的内容

iOS: Dynamic Marker Info Window iOS:动态标记信息窗口

https://developers.google.com/maps/documentation/ios/marker#info_windows https://developers.google.com/maps/documentation/ios/marker#info_windows

I solved a similar problem by setting: 我通过设置解决了类似的问题:

marker.tracksInfoWindowChanges = true

in mapView markerInfoWindow and then after image is loaded (ie in "success:" completion handler, I set the image and then set: 在mapView markerInfoWindow中,然后加载图像后(即在“成功:”完成处理程序中,我设置图像,然后设置:

marker.tracksInfoWindowChanges = false

Also see the offical docs for tracksInfoWindowChanges here . 请参阅此处的tracksInfoWindowChanges官方文档

I solved the problem as following 我解决了以下问题

I use this property as the info window. 我将此属性用作信息窗口。

@property (nonatomic) MyInfoWindow* infoWindow 

And this is how I wrote the delegate method of GMSMapViewDelegate 这就是我编写GMSMapViewDelegate的委托方法的方式

- (UIView*)mapView:(GMSMapView*)mapView markerInfoWindow:(GMSMarker*)marker
{
    //Prepare Data
    MyEvent* selectedEvent = [EventManager eventForEventID:marker.objectID];
    //Prepare Thumbnail URL
    NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[selectedEvent getSmallBannerWithSize:@"w50"]];

    //Prepare InfoView's UIView
    _infoWindow = [[[NSBundle mainBundle] loadNibNamed:@"infoWindowView" owner:self options:nil] objectAtIndex:0];
    _infoWindow.title.text = selectedEvent.eventName;

    //Get cached image from AFNetworking
    UIImage* img = [[UIImageView sharedImageCache] cachedImageForRequest:request];
    if (img == nil) {
        [_infoWindow.thumbnail setImageWithURLRequest:request 
                               placeholderImage:[UIImage imageNamed:@"placeholder"] 
          success:^(NSURLRequest* request, NSHTTPURLResponse* response, UIImage* image) {
            //Invoke selection to call this delegate method again
            [mapView setSelectedMarker:marker]; 
        } failure:^(NSURLRequest* request, NSHTTPURLResponse* response, NSError* error) {
            NSLog(@"RY fetching thumbnail image error : %@", request);
        }];
    } else {
        // If we can get the cached image, which means the image is downloaded, 
        // then update the info window
        _infoWindow.thumbnail.image = img;
    }
    return _infoWindow;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不点击标记的情况下在 iOS 谷歌地图中显示信息窗口? - How to show a Info window in iOS Google maps without tapping on Marker? Google Maps在标记信息窗口iOS中显示语音气泡 - Google Maps Showing speechbubble in marker info window iOS Google Maps SDK iOS - 带UIButton的自定义标记信息窗口 - Google Maps SDK iOS - Custom marker info window with UIButton 以编程方式谷歌地图iOS的标记的关闭信息窗口 - Close info window of a marker programmatically google maps iOS 如何在iOS谷歌地图中显示所有信息窗口而无需点击标记? - How to show all Info window in iOS Google maps without tapping on Marker? 如何在ios上添加一个按钮到谷歌地图标记信息窗口? - How can i add a button to google maps marker info window on ios? 谷歌地图ios - 如何始终显示标记信息窗口? - Google map ios - how to keep the marker info window always displayed? 在Google地图上加载标记的自定义信息窗口时,iOS应用程序冻结 - iOS app freezes when loading custom info window for marker on Google Maps ios谷歌地图绘制多个标记问题(信息窗口和标记重复) - ios google maps plotting multiple markers issues(info window and marker repeating) 如何在iOS右侧显示Google Maps信息窗口 - How to display a Google Maps info window on the right side in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM