【问题标题】:MapView not reloading annotations unless you zoom in or move map除非您放大或移动地图,否则 MapView 不会重新加载注释
【发布时间】:2014-05-31 23:32:14
【问题描述】:

我正在使用以下for循环来管理/找出距离用户位置最近的五个注释,然后将它们设置为mapView的注释。

for (int i = 0; i <= 5; i++) {
            //NSLog(@"Stores Count For Loop: %i", [storesLessThan100KAway count]);
            if ([storesLessThan100KAway count] > 5) {
                NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"distanceToTarget" ascending:YES];
                NSArray *newArray = [storesLessThan100KAway sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
                [mapView addAnnotation:[newArray objectAtIndex:i]];
                if ([[mapView annotations] count] > 4) {
                    [descriptor release];
                    [dict release];
                    [currentlocation release];
                    [usrlocation release];
                    [annotation release];
                    [paul drain];
                    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
                    return;
                }
            }

但是,在地图放大或移动之前,不会显示添加到地图的注释。无论如何我可以阻止它吗?

【问题讨论】:

    标签: iphone objective-c xcode ios4 android-mapview


    【解决方案1】:

    MKMapView 是 UIView 的子类 -- 你可以尝试调用 [mapView setNeedsDisplay]?

    如果这不起作用:

    // Force update of map view.
    CLLocationCoordinate2D center = [mapView centerCoordinate];
    [mapView setCenterCoordinate:center];
    

    【讨论】:

    • 我实际上尝试缩放到用户位置(为了用户体验)。
    • 我遇到了完全相同的问题...您是如何解决的?上面的答案对我不起作用。(在这里查看我的问题:stackoverflow.com/questions/6590958/…
    【解决方案2】:

    尝试将这些行放入 Timer 并在完成添加注释后停止它

    static float deltaX=.1;
    CLLocation *location = [[[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude] autorelease];
    
    MKCoordinateRegion region;
    region.center = location.coordinate;
    MKCoordinateSpan span;
    
    span.latitudeDelta = self.mapView.region.span.latitudeDelta+deltaX;
    span.longitudeDelta = self.mapView.region.span.longitudeDelta+deltaX;
    deltaX+=.1;
    deltaX*=-1;
    region.span = span; // Set the region's span to the new span.
    [self.mapView setRegion:region animated:0];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-11
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 2017-02-16
      • 2020-07-03
      相关资源
      最近更新 更多