<i id='tHRnR'><tr id='tHRnR'><dt id='tHRnR'><q id='tHRnR'><span id='tHRnR'><b id='tHRnR'><form id='tHRnR'><ins id='tHRnR'></ins><ul id='tHRnR'></ul><sub id='tHRnR'></sub></form><legend id='tHRnR'></legend><bdo id='tHRnR'><pre id='tHRnR'><center id='tHRnR'></center></pre></bdo></b><th id='tHRnR'></th></span></q></dt></tr></i><div id='tHRnR'><tfoot id='tHRnR'></tfoot><dl id='tHRnR'><fieldset id='tHRnR'></fieldset></dl></div>
  • <tfoot id='tHRnR'></tfoot>
      <bdo id='tHRnR'></bdo><ul id='tHRnR'></ul>

      <small id='tHRnR'></small><noframes id='tHRnR'>

        <legend id='tHRnR'><style id='tHRnR'><dir id='tHRnR'><q id='tHRnR'></q></dir></style></legend>
      1. IOS:将图像添加到自定义 MKAnnotationview

        时间:2023-09-01

        1. <small id='s6qPJ'></small><noframes id='s6qPJ'>

            <tbody id='s6qPJ'></tbody>
          <legend id='s6qPJ'><style id='s6qPJ'><dir id='s6qPJ'><q id='s6qPJ'></q></dir></style></legend>
          <i id='s6qPJ'><tr id='s6qPJ'><dt id='s6qPJ'><q id='s6qPJ'><span id='s6qPJ'><b id='s6qPJ'><form id='s6qPJ'><ins id='s6qPJ'></ins><ul id='s6qPJ'></ul><sub id='s6qPJ'></sub></form><legend id='s6qPJ'></legend><bdo id='s6qPJ'><pre id='s6qPJ'><center id='s6qPJ'></center></pre></bdo></b><th id='s6qPJ'></th></span></q></dt></tr></i><div id='s6qPJ'><tfoot id='s6qPJ'></tfoot><dl id='s6qPJ'><fieldset id='s6qPJ'></fieldset></dl></div>

            • <bdo id='s6qPJ'></bdo><ul id='s6qPJ'></ul>
                <tfoot id='s6qPJ'></tfoot>

                  本文介绍了IOS:将图像添加到自定义 MKAnnotationview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在地图中的注释中添加自定义图像.我已经制作了以下自定义 MapAnnotationView:

                  I want to add a custom image to my annotations in the map. And i have made the following custom MapAnnotationView:

                  #import <UIKit/UIKit.h>
                  #import <Foundation/Foundation.h>
                  #import <MapKit/MapKit.h>
                  #import <CoreLocation/CoreLocation.h>
                  @class POI;
                  
                  @interface MapAnnotation : MKAnnotationView <MKAnnotation >
                  
                  @property (nonatomic) CGFloat lat; 
                  @property (nonatomic) CGFloat lon;
                  @property (nonatomic) CGFloat altitude; 
                  @property (nonatomic,  copy) NSString * title;
                  @property (nonatomic, copy) NSString * subtitle;
                  @property (nonatomic,retain) NSString *source;
                  @property (nonatomic,retain) UIImage  *image;
                  
                  @end
                  
                  @implementation MapAnnotation
                  @synthesize coordinate;
                  @synthesize lat=_lat,lon=_lon,altitude= _altitude;
                  @synthesize subtitle= _subtitle, title= _title, source=_source, image =_img;
                  
                  
                  - (CLLocationCoordinate2D)coordinate;{
                      CLLocationCoordinate2D position;
                      if (_lat != 0.0 && _lon != 0.0) {
                          position.latitude = _lat;
                          position.longitude = _lon;
                  
                      }else {
                          position.latitude=0.0;
                          position.longitude=0.0;
                      }
                  
                      return position; 
                  }
                  
                  @end
                  
                  -(void) mapDataToMapAnnotations{
                  
                      NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:10];
                      for (id annotation in _map.annotations)
                          if (annotation != _map.userLocation)
                              [toRemove addObject:annotation];
                      [_map removeAnnotations:toRemove];
                  
                      [_data removeAllObjects];
                  
                      [_data addObjectsFromArray:[UDdelegate naturArray]];
                  
                  
                      if(_data != nil){
                          MapAnnotation * tmpPlace;
                          //for(NSDictionary * poi in _data){
                  
                  
                          for(POI* poi in _data){
                  
                              tmpPlace = [[MapAnnotation alloc]init];
                  
                              tmpPlace.title = [poi title];
                              tmpPlace.lat = [poi lat];
                              tmpPlace.lon = [poi lon];
                              tmpPlace.subtitle = [poi dist];
                              tmpPlace.image = [poi poiIcon];
                  
                              [self.map addAnnotation:tmpPlace];
                              [_map setNeedsLayout];
                          }
                      }
                  }
                  

                  问题是引脚是标准的 redPin.... 我确定图标不为空,已经检查过了.

                  The problem is that the pins is the standard redPin.... I am sure that the icons isn't null, have checked for that.

                  谢谢

                  推荐答案

                  您必须为 MapKit 委托方法 mapView:viewForAnnotation: 提供自定义视图.

                  You have to serve the MapKit delegate method mapView:viewForAnnotation: with a custom view.

                  - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
                  {
                      static NSString *annotationViewReuseIdentifier = @"annotationViewReuseIdentifier";
                  
                      MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationViewReuseIdentifier];
                  
                      if (annotationView == nil)
                      {
                          annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationViewReuseIdentifier] autorelease];
                      }
                  
                      annotationView.image = [UIImage imageNamed:@"pin_image.png"];
                      annotationView.annotation = annotation;
                  
                      return annotationView;
                  }
                  

                  要封装更多内容,您应该像以前一样创建一个自定义注释视图,并将上面的委托方法与您的类一起提供.

                  To encapsulate more you should create a custom annotation view like you did and serve the delegate method above with your class.

                  我建议您重命名 MapAnnotation 类,因为它会造成混淆.iOS 中还有注释,它们是这些注释视图的数据持有者.为了解决这个问题,我更喜欢编写继承类的类型,在这种情况下,MKAnnotationView 在自定义类的末尾.例如 CustomPinAnnotationView.

                  I advise you to rename the MapAnnotation class because it is confusing. There are also Annotations in iOS which are the data holders for those annotation views. To solve this I would prefer to write the type of the inherited class, in this case MKAnnotationView at the end of your custom class. For example CustomPinAnnotationView.

                  这篇关于IOS:将图像添加到自定义 MKAnnotationview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 LocationClient 定期获取更新最省电的方法是什 下一篇:根据可用性在 gps 和网络提供商之间切换

                  相关文章

                  最新文章

                    <legend id='BRFXF'><style id='BRFXF'><dir id='BRFXF'><q id='BRFXF'></q></dir></style></legend>

                    <i id='BRFXF'><tr id='BRFXF'><dt id='BRFXF'><q id='BRFXF'><span id='BRFXF'><b id='BRFXF'><form id='BRFXF'><ins id='BRFXF'></ins><ul id='BRFXF'></ul><sub id='BRFXF'></sub></form><legend id='BRFXF'></legend><bdo id='BRFXF'><pre id='BRFXF'><center id='BRFXF'></center></pre></bdo></b><th id='BRFXF'></th></span></q></dt></tr></i><div id='BRFXF'><tfoot id='BRFXF'></tfoot><dl id='BRFXF'><fieldset id='BRFXF'></fieldset></dl></div>

                  1. <tfoot id='BRFXF'></tfoot>

                    <small id='BRFXF'></small><noframes id='BRFXF'>

                      • <bdo id='BRFXF'></bdo><ul id='BRFXF'></ul>