I am developing an iphone app,ı show radar points on MapView.There are over 1000 points. I have to show all points and calculate distances between radar points and user location points. I have to create all regions (over 1000) to show? Can anyone give me an idea, how can I use for loop to make this? otherwise I will create over 1000 region objects. Here is my code:
- (void)viewDidLoad {
//user's location information
CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude longitude:self.mapView.userLocation.coordinate.longitude];
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
//region1
MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region1.center.latitude = 39.9828000 ;
region1.center.longitude =26.3033200 ;
region1.span.longitudeDelta = 1.90f;
region1.span.latitudeDelta = 0.00f;
[mapView setRegion:region1 animated:YES];
[mapView setDelegate:self];
DisplayMap *ann1 = [[DisplayMap alloc] init]; //display is my class to keep title,subtitle and coordinate information.
ann1.title = @" istanbul";
ann1.subtitle = @"esenler";
ann1.coordinate = region1.center;
[mapView addAnnotation:ann1];
CLLocation *pinLocation1 = [[CLLocation alloc] initWithLatitude:region1.center.latitude longitude:region1.center.longitude];
CLLocationDistance distance1 = [pinLocation1 distanceFromLocation:userLocation];
if(distance1<20000){
[lbl setText: [NSString stringWithFormat:@"Distance to point %4.2f m.",distance1]];
}
//region2
MKCoordinateRegion region2 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region2.center.latitude = 39.9876200 ;
region2.center.longitude =26.3062700 ;
region2.span.longitudeDelta = 1.90f;
region2.span.latitudeDelta = 0.00f;
[mapView setRegion:region2 animated:YES];
[mapView setDelegate:self];
DisplayMap *ann2 = [[DisplayMap alloc] init];
ann2.title = @" istanbul";
ann2.subtitle = @"esenler";
ann2.coordinate = region2.center;
[mapView addAnnotation:ann2];
//aradaki uzaklığı hesaplamak için mevcut yerin location ı cllocation class ı üzerinden hesaplanıyor.
CLLocation *pinLocation2 = [[CLLocation alloc] initWithLatitude:region2.center.latitude longitude:region2.center.longitude];
CLLocationDistance distance2 = [pinLocation2 distanceFromLocation:userLocation];
if(distance2<20000){
[lbl setText: [NSString stringWithFormat:@"Distance to point %4.2f m.",distance2]];
}
}