菜鸟教程小白 发表于 2022-12-13 11:38:14

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


                                            <p><p>我在使用 SKMaps for iOS 时遇到问题。似乎它没有加载注释。它应该在湖周围的某处显示注释</p>

<p> <img src="/image/M8kns.png" alt=""/> </p>

<p>同样在初始化时,不去指定区域。</p>

<p>初始化映射方法</p>

<pre><code>-(void) initMap {
    /*
   self.mapView = [ initWithFrame:CGRectMake(0.0f, 0.0f,
      CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
    */
    self.mapView = [ 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;

    //;
    //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 addAnotation:CLLocationCoordinate2DMake(14.7241845,121.085998)
          annotationId:1
             imageName:nil
         imageHeight:0.0f
            imageWidth:0.0f
       skAnotationType:SKAnnotationTypePurple];
}
</code></pre>

<p>AddAnnotation 方法</p>

<pre><code>-(void)addAnotation:(CLLocationCoordinate2D) coordinate annotationId:(int) annotationId
      imageName:(NSString*)imageName imageHeight:(float) imageHeight imageWidth:(float)
      imageWidth skAnotationType:(SKAnnotationType) skAnotationType {

;

SKAnnotation *annotation = ;
annotation.identifier = annotationId;
annotation.location = coordinate; //CLLocationCoordinate2DMake(52.5237, 13.4137);
SKAnimationSettings *animationSettings = ;

if(imageName.length==0 || imageName == (id))
{
    annotation.annotationType = skAnotationType;      
} else {
    //Annotation with view
    //create our view
    UIImageView *coloredView = [ initWithFrame:
      CGRectMake(0.0, 0.0, 128.0, 128.0)];
    coloredView.image = ;

    //create the SKAnnotationView
    SKAnnotationView *view = [ initWithView:coloredView
      reuseIdentifier:@&#34;viewID&#34;];

    //set the custom view
    annotation.annotationView = view;

}
;
//;}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>设置可见区域以及添加带有自定义 View 的注释都有效。这是在我们的演示项目中工作的代码:</p>

<pre><code>UIImageView *customAnnotationView = [ initWithFrame:CGRectMake(0, 0, 50, 50)];
    customAnnotationView.backgroundColor = ;
    customAnnotationView.image = ; //&#34;santa.png&#34; was added to resources

    SKAnnotationView *annotationView = [ initWithView:customAnnotationView reuseIdentifier:@&#34;reusableIdentifier&#34;];

    SKAnnotation *annotation = ;
    annotation.identifier = 123456;
    annotation.location = region.center;
    annotation.annotationView = annotationView;

    ];
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iOS SKMaps 不加载注释(Xcode 6,Objective C),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/33408772/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/33408772/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS SKMaps 不加载注释(Xcode 6,Objective C)