0

iPhoneで異なる緯度と経度の値を使用して複数のピンをドロップするにはどうすればよいですか?

10 の緯度と経度の値があります。したがって、これらの値を使用して、マップに 10 個のピンをドロップする必要があります (緯度の値の数によって異なります)。

4

1 に答える 1

1

場所マークを付けるためのクラスを作成する

#import <MapKit/MapKit.h>

@interface DDAnnotation : MKPlacemark 

// Re-declare MKAnnotation's readonly property 'coordinate' to readwrite. 
@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;

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

@end

/////// 黙示

#import "DDAnnotation.h"

@implementation DDAnnotation

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

すべての場所情報 (緯度と経度を含む) を入れます self.listOfPlaces

- (void)showAllPlaces
{

    for(int i=0; i<self.listOfPlaces.count; i++)
    {
        NSMutableDictionary *cPlace = [self.listOfPlaces objectAtIndex:i];
        CLLocationCoordinate2D pCoordinate ;
        pCoordinate.latitude = [[cPlace objectForKey:@"latitude"] doubleValue];
        pCoordinate.longitude = [[cPlace objectForKey:@"longitude"] doubleValue];

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

        annotation.title = [cPlace objectForKey:@"placeName"];
        annotation.subtitle = [cPlace objectForKey:@"placeDescription"];
        annotation.image = [cPlace objectForKey:@"markerImage"];
        annotation.placeID = [cPlace objectForKey:@"placeID"];

        [self.mapView addAnnotation:annotation];
    }
    }
于 2013-02-07T13:44:20.007 に答える