简体   繁体   中英

SKMaps iOS: Pin disappears when panning the Map

With the new Version (2.1.0) I get a problem. The Annotation disappears when scrolling the map. In the demo project it works fine. Also adding the frameworks again doesn't help.

- (void)viewDidLoad {
    [super viewDidLoad];

    placeDetail = [[PlaceDetailViewController alloc] init];
    latitude = [placeDetail Latitude];
    longitude = [placeDetail Longitude];

    self.placeMapView = [[SKMapView alloc] init];
    self.placeMapView.frame = CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
    self.placeMapView.delegate = self;
    self.placeMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.placeMapView.settings.poiDisplayingOption = SKPOIDisplayingOptionNone;
    [self.view addSubview:self.placeMapView];

    //add a circle overlay
    for(int i=0;i<latitude.count;i++)
    {
        //set the map region
        SKCoordinateRegion region;
        region.center = CLLocationCoordinate2DMake([latitude[i] floatValue], [longitude[i] floatValue]);
        region.zoomLevel = 17;
        self.placeMapView.visibleRegion = region;

        SKAnnotation *mapAnnotation = [SKAnnotation annotation];
        mapAnnotation.identifier = i;
        mapAnnotation.minZoomLevel = 5;

        mapAnnotation.annotationType = SKAnnotationTypeRed;
        mapAnnotation.location = CLLocationCoordinate2DMake([latitude[i] floatValue], [longitude[i] floatValue]);

        [self.placeMapView addAnnotation:mapAnnotation];
    }
}

Annoation creation

-(void)mapView:(SKMapView *)mapView didSelectAnnotation:(SKAnnotation *)annotation {

    self.placeMapView.calloutView.titleLabel.text= placeDetail.Name;
    self.placeMapView.calloutView.titleLabel.font = [UIFont fontWithName:@"PTSans-Narrow" size:15];
    self.placeMapView.calloutView.subtitleLabel.text = @"";
    [self.placeMapView showCalloutForAnnotation:annotation withOffset:CGPointMake(0, 42) animated:YES];
    [self.placeMapView.calloutView.rightButton addTarget:self action:@selector(backToDetailView) forControlEvents:UIControlEventTouchUpInside];
}

I would appreciate your help.

EDIT: I think I found the problem that causes this beahvior. In my app I have two kind of maps. One Mini Map and one large Map. But in two different views. When I deactivate the Mini Map it works. SO I think it has to do with the loading of the SKMap framework. Currently the mini map function is called in view did load method. So you know what to do here?

It is a bug in the 2.1 and 2.2 versions of the SDK - it will be fixed in 2.3 (eta November 2014).

For 2.1/2.2 there is a workaround: having different id's for the annotations on the minimap and the big map. For example you have N annotations on the minimap with ids 0..N-1, then the big map would have annotations with ids from N onward. So for M annotations on the big map you would have annotations with ids from N..M-1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM