0

カスタム アノテーション クラスをマップビューに追加するときに、そのクラスにアクセスできません。カスタム クラスは正常に動作していますが、それをマップに追加すると、このデリゲートを介してカスタム アノテーションにアクセスする方法がわかりません。

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation

私はオンラインで探してみましたが、何も見つかりませんでした。どんな助けでも素晴らしいでしょう。

次のように呼び出されます。

CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(shops.latitude, shops.longitude);
    AnnotationForId *shop = [[AnnotationForId alloc] initWithCoordinate:coords];
    //[[CLLocationCoordinate2DMake(shops.latitude, shops.longtitude)]];
    shop.title = shops.name;
    shop.subtitle = @"Coffee Shop";
    shop.shopId = shops.id;
    [map addAnnotation:shop];
4

2 に答える 2

1

これは、カスタム AnnotationView を作成する方法の簡単な例です。

カスタムを作成AnnotationView:

#import <MapKit/MapKit.h>

@interface AnnotationView : MKPlacemark

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *subtitle;

// you can put here any controllers that you want. (such like UIImage, UIView,...etc)

@end

そして、.m file

#import "AnnotationView.h"

@implementation AnnotationView

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary
{
    if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary]))
    {
        self.coordinate = coordinate;
    }
    return self;
}

@end

// 関連する Annotation Add を使用#import "AnnotationView.h"します.m file:

CLLocationCoordinate2D pCoordinate ;
pCoordinate.latitude = LatValue;
pCoordinate.longitude = LanValue;

// Create Obj Of  AnnotationView class  

AnnotationView *annotation = [[AnnotationView alloc] initWithCoordinate:pCoordinate addressDictionary:nil] ;

    annotation.title = @"I m Here";
    annotation.subtitle = @"This is Sub Tiitle";

[self.mapView addAnnotation:annotation];
于 2013-03-28T14:23:01.823 に答える