Reputation: 99
I need to add 'xx' amout of random annotations to an MKMapView, within a certain range of the user's current location. But i can't figure out how to do it.
Can some of you help me?
Upvotes: 1
Views: 786
Reputation: 41
Something like this might help:
for(int i=0;i<10;i++) {
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
CLLocationCoordinate2D newCoord = {myLocation.coordinate.latitude+latDelta, myLocation.coordinate.longitude+lonDelta};
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = @"Some Pin";
ann.subtitle = [NSString stringWithFormat:@"Pin %i subtitle",i+1];
ann.coordinate = newCoord;
[mapView addAnnotation:ann];
[ann release];
}
where: myLocation is a CLLocation instance. DisplayMap is:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface DisplayMap : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;
@end
Upvotes: 1