[英]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.