繁体   English   中英

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

[英]iOS SKMaps not loading annotations (Xcode 6, Objective C)

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

设置可见区域有效,以及添加带有自定义视图的注释。 这是在我们的演示项目中工作的代码:

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]];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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