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 回答