Show current position annotation by default

北城余情 提交于 2019-12-08 00:59:17

问题


I have an current location annotation (blue dot) showing in mapkit. Annotation shows after taping the blue dot, how can I have the annotation showing by default?, when I start the view? whit out tapping the pin.

 - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {
    for(MKAnnotationView *annotationView in views) {
        if(annotationView.annotation == mv.userLocation) {

            self.mapView.userLocation.title= @"Current";
            self.mapView.userLocation.subtitle= @"Location";

            MKCoordinateRegion region;
            MKCoordinateSpan span;

            span.latitudeDelta=0.002;
            span.longitudeDelta=0.002; 

            CLLocationCoordinate2D location=mv.userLocation.coordinate;

            region.span=span;
            region.center=location;

            [mv setRegion:region animated:YES];
            [mv regionThatFits:region];

        }
    }

}

回答1:


In that case, selectAnnotation should work, wouldn't it? Just performSelector after a small time.

.... same code as before but insert this:

            id annotation = annotationView.annotation;
            [self performSelector:@selector(selectUserLocation:) withObject:annotation afterDelay:0.1f];
        }
    }
}

- (void)selectUserLocation:(id)annotation{
    [self.mapView selectAnnotation:annotation animated:YES];
}


来源:https://stackoverflow.com/questions/10555583/show-current-position-annotation-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!