I'm trying to fetch the particular details on which MapAnnotation
the user clicks.the details are fetched from plist
file. for this function i've used - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view;
on using this.while i click on particular annotation
it fetches location details fromMap
as "Pune, Maharashtra, India @ <+18.50565666,+73.85559082> +/- 0.00m"
and it does not checks my plist values.even after i given these values as attributes in plist as latlong for each location.can anybody solve my problem?
My plist file details:
2013-02-18 12:16:56.039 MapView[9407:13d03] {
contents = "This Fish will be Found Rarely in South Asia";
imagesName = "kfish.jpg";
latlong = "Bangalore, Karnataka, India @ <+12.98333330,+77.58333330> +/- 0.00m";
listName = kFish;
location = "Bangalore, Karnataka, India";
}
2013-02-18 12:16:56.039 MapView[9407:13d03] {
contents = "This Fish will be Found Rarely in South Asia";
imagesName = "wallfish.png";
latlong = "Delhi, India @ <+28.59100531,+77.08826373> +/- 0.00m";
listName = WallFish;
location = "Delhi, India";
}
2013-02-18 12:16:56.039 MapView[9407:13d03] {
contents = "This Fish will be Found Rarely in South Asia";
imagesName = "fish.jpg";
latlong = "Chennai, Tamil Nadu, India @ <+13.07983465,+80.24625757> +/- 0.00m";
listName = Fish;
location = "Chennai,TamilNadu,India";
}
2013-02-18 12:16:56.039 MapView[9407:13d03] {
contents = "This Fish will be Found Rarely in South Asia";
imagesName = "bluefish.jpg";
latlong = "Mumbai, Maharashtra, India @ <+18.99460885,+72.82287598> +/- 0.00m";
listName = BlueFish;
location = "Mumbai, Maharashtra, India";
}
2013-02-18 12:16:56.040 MapView[9407:13d03] {
contents = "This Fish will be Found Rarely in South Asia";
imagesName = "Rarefish.jpg";
latlong = "Chennai, Tamil Nadu, India @ <+13.07983465,+80.24625757> +/- 0.00m";
listName = RareFish;
location = "Chennai,TamilNadu,India";
}
My Coding:
- (void)geocodeRequest
{
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
for (int i = 0; i < total; i++) {
NSString *address = [allValues objectAtIndex:i] ;
[geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:geocodedPlacemark.location.coordinate addressDictionary:geocodedPlacemark.addressDictionary];
int zoomLevel=20;
MKCoordinateRegion region=MKCoordinateRegionMake(geocodedPlacemark.location.coordinate, MKCoordinateSpanMake(zoomLevel,zoomLevel));
[self.mapView addAnnotation:placemark];
[self.mapView setRegion:region animated:YES];
[self.mapView setZoomEnabled:YES];
}];
}
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
total = self.arrayImages.count;
NSArray *newIndex = [mapView selectedAnnotations];
NSLog(@"sel :%@",newIndex);
for (index = 0; index < total; index++) {
dict = [self.arrayImages objectAtIndex:index];
NSLog(@"%@",dict);
if (latlong == newIndex) {
CGRect rec = CGRectMake(0, 0, 250, 250);
[self setView:[[[UIView alloc] initWithFrame:rec] autorelease]];
[[self view] setBackgroundColor:[UIColor whiteColor]];
UIImage *img = [UIImage imageNamed:[dict objectForKey:@"imagesName"]];
UIImageView *im = [[UIImageView alloc] initWithImage:img];
UILabel *lab1 = [[UILabel alloc] init];
UITextView *detailsView = [[UITextView alloc] init];
lab1.text = [NSString stringWithFormat:[dict objectForKey:@"listName"]];
detailsView.text = [NSString stringWithFormat:[dict objectForKey:@"contents"]];
detailsView.editable = NO;
detailsView.bounds = CGRectMake(20, 20, 150, 150);
detailsView.frame = CGRectMake(210, 720, 390, 350);
detailsView.font = [UIFont systemFontOfSize:24];
lab1.bounds = CGRectMake(20, 20, 150, 150);
lab1.frame = CGRectMake(360, 600, 90, 50);
lab1.font = [UIFont systemFontOfSize:24];
im.bounds = CGRectMake(10, 10, 50, 50);
im.frame = CGRectMake(200, 120, 370, 450);
[UIView transitionWithView:[self view] duration:1.5
options:UIViewAnimationOptionTransitionCurlUp
animations:^ { [[self view] addSubview:im];
[[self view] addSubview:lab1];
[[self view] addSubview:detailsView];
}completion:nil];
}
}
}
MapView Works fine.but on fetching the selected location only it's not working.can anybody help me where have i went wrong??
Thanks In Advance.