iOS SKMaps 不加载注释(Xcode 6,Objective C)

标签 ios objective-c xcode skmaps

我在使用 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];
}

添加注释方法

-(void)addAnotation:(CLLocationCoordinate2D) coordinate annotationId:(int) annotationId
        imageName:(NSString*)imageName imageHeight:(float) imageHeight imageWidth:(float) 
        imageWidth skAnotationType:(SKAnnotationType) 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/

相关文章:

ios - 计算 Twitter 字符数

ios - Swift:ProtocolDelegate 可选值错误

ios - Opengl ES 裁剪和背面剔除

ios - UIScrollViews 并在其上添加组件

node.js - Xcode Build react native 代码和图像未找到 Node

iphone - 如何运行Three20单元测试?

ios - 如何将 iOS 6.1 DocSets 从 Xcode 4 导入到 Xcode 5

iOS:加载没有 nib 文件的第二个 View Controller

iphone - 2 个控制点的 Shephard 扭曲会扭曲整个图像 - ImageMagick Iphone sdk

objective-c - 在运行时对 ObjectiveC 字符串进行字符串化