Objective c MKMapView未刷新批注
显然,我有一个MKMapView,它显示了用户周围的住房位置 我有一个半径工具,当进行选择时,注释应该根据用户周围的距离添加/删除 我有它添加/删除罚款,但由于某种原因,注释不会显示,直到我放大或缩小 这是基于距离添加/删除注释的方法。我尝试了两种不同的方法 将新注释添加到数组中,然后通过[mapView addAnnotations:NSArray]将其添加到地图中 使用[mapView addAnnotation:MKMapAnnotation]添加找到的注释 一, 此外,要在可能工作的地方强制刷新saw,请执行以下操作:Objective c MKMapView未刷新批注,objective-c,ios,xcode,annotations,mkmapview,Objective C,Ios,Xcode,Annotations,Mkmapview,显然,我有一个MKMapView,它显示了用户周围的住房位置 我有一个半径工具,当进行选择时,注释应该根据用户周围的距离添加/删除 我有它添加/删除罚款,但由于某种原因,注释不会显示,直到我放大或缩小 这是基于距离添加/删除注释的方法。我尝试了两种不同的方法 将新注释添加到数组中,然后通过[mapView addAnnotations:NSArray]将其添加到地图中 使用[mapView addAnnotation:MKMapAnnotation]添加找到的注释 一, 此外,要在可能工作的地方
self._mapView.showsUserLocation = NO;
self._mapView.showsUserLocation = YES;
非常感谢您的帮助,并一如既往地感谢您抽出时间阅读 我猜updateBasedDistance:是从后台线程调用的。核对NSLog@Am我在UI线程中找到了%d、 [NSThread isMainThread];。如果为0,则应将removeAnnotations:和addAnnotation:移动到performSelectorOnMainThread:调用,或将GCD块移动到主线程上。我猜updateBasedDistance:是从后台线程调用的。核对NSLog@Am我在UI线程中找到了%d、 [NSThread isMainThread];。如果为0,则应将removeAnnotations:和addAnnotation:移动到performSelectorOnMainThread:调用,或在主线程上使用GCD块。Ah!为什么我没看到呢。谢谢你,先生。谢谢你,我也有同样的问题,这个问题解决了。你帮我省了至少几个小时的头痛。啊!为什么我没看到呢。谢谢,先生。谢谢,我也遇到了同样的问题,这个问题解决了。你帮我省了至少几个小时的头痛。
- (void)updateBasedDistance:(NSNumber *)distance {
//Setup increment for HUD animation loading
float hudIncrement = ( 1.0f / [[[[self appDelegate] rssParser]rssItems] count]);
//Remove all the current annotations from the map
[self._mapView removeAnnotations:self._mapView.annotations];
/*
I have an array that holds all the annotations on the map becuase
a lot of filtering/searching happens. So for memory reasons it is
more efficient to load annoations once then add/remove as needed.
*/
for (int i = 0; i < [annotations count]; i++) {
//Current annotations location
CLLocation *tempLoc = [[CLLocation alloc] initWithLatitude:[[annotations objectAtIndex:i] coordinate].latitude longitude:[[annotations objectAtIndex:i] coordinate].longitude];
//Distance of current annotaiton from user location converted to miles
CLLocationDistance miles = [self._mapView.userLocation.location distanceFromLocation:tempLoc] * 0.000621371192;
//If distance is less than user selection, add it to the map.
if (miles <= [distance floatValue])
[self._mapView addAnnotation:[annotations objectAtIndex:i]];
//For some reason, even with ARC, helps a little with memory consumption
tempLoc = nil;
//Update a progress HUD I use.
HUD.progress += hudIncrement;
}
}
[self._mapView setNeedsDisplay];
[self._mapView setNeedsLayout];
self._mapView.showsUserLocation = NO;
self._mapView.showsUserLocation = YES;