• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 11:38:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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



Best Answer-推荐答案


设置可见区域以及添加带有自定义 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap