我在使用 SKMaps for iOS 时遇到问题。似乎它没有加载注释。它应该在湖周围的某处显示注释
同样在初始化时,不去指定区域。
初始化映射方法
-(void) initMap {
/*
self.mapView = [[SKMapView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,
CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
*/
self.mapView = [[SKMapView alloc] initWithFrame:
CGRectMake(0.0f, 0.0f, 238.0f, 157.0f)];
self.mapView.autoresizingMask
= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// set initial coordinates
// la mesa dam
//_loc2DLamesaDam = CLLocationCoordinate2DMake(14.7241845,121.085998);
SKCoordinateRegion region;
region.center = CLLocationCoordinate2DMake(14.7241845,121.085998);
region.zoomLevel = 17;
self.mapView.visibleRegion = region;
//[self.view addSubview:mapView];
//show the compass
self.mapView.settings.showCompass = YES;
//hide the map scale
self.mapView.mapScaleView.hidden = YES;
self.mapView.settings.rotationEnabled = NO;
self.mapView.settings.followUserPosition = YES;
SKMapZoomLimits zoomLimits;
zoomLimits.mapZoomLimitMax = 17;
zoomLimits.mapZoomLimitMin = 10;
self.mapView.settings.zoomLimits = zoomLimits;
self.mapView.settings.headingMode = SKHeadingModeRotatingMap;
[self determineMapStyle];
[self addAnotation:CLLocationCoordinate2DMake(14.7241845,121.085998)
annotationId:1
imageName:nil
imageHeight:0.0f
imageWidth:0.0f
skAnotationType:SKAnnotationTypePurple];
}
AddAnnotation 方法
-(void)addAnotationCLLocationCoordinate2D) coordinate annotationIdint) annotationId
imageNameNSString*)imageName imageHeightfloat) imageHeight imageWidthfloat)
imageWidth skAnotationTypeSKAnnotationType) skAnotationType {
[mapView removeAnnotationWithID:annotationId];
SKAnnotation *annotation = [SKAnnotation annotation];
annotation.identifier = annotationId;
annotation.location = coordinate; //CLLocationCoordinate2DMake(52.5237, 13.4137);
SKAnimationSettings *animationSettings = [SKAnimationSettings animationSettings];
if(imageName.length==0 || imageName == (id)[NSNull null])
{
annotation.annotationType = skAnotationType;
} else {
//Annotation with view
//create our view
UIImageView *coloredView = [[UIImageView alloc] initWithFrame:
CGRectMake(0.0, 0.0, 128.0, 128.0)];
coloredView.image = [UIImage imageNamed:imageName];
//create the SKAnnotationView
SKAnnotationView *view = [[SKAnnotationView alloc] initWithView:coloredView
reuseIdentifier"viewID"];
//set the custom view
annotation.annotationView = view;
}
[self.mapView addAnnotation:annotation withAnimationSettings:animationSettings];
//[mapView addAnnotation:viewAnnotation withAnimationSettings:animationSettings];}
设置可见区域以及添加带有自定义 View 的注释都有效。这是在我们的演示项目中工作的代码:
UIImageView *customAnnotationView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
customAnnotationView.backgroundColor = [UIColor greenColor];
customAnnotationView.image = [UIImage imageNamed"santa"]; //"santa.png" was added to resources
SKAnnotationView *annotationView = [[SKAnnotationView alloc] initWithView:customAnnotationView reuseIdentifier"reusableIdentifier"];
SKAnnotation *annotation = [SKAnnotation annotation];
annotation.identifier = 123456;
annotation.location = region.center;
annotation.annotationView = annotationView;
[self.mapView addAnnotation:annotation withAnimationSettings:[SKAnimationSettings animationSettings]];
关于iOS SKMaps 不加载注释(Xcode 6,Objective C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33408772/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |