我正试图获取用户点击的具体详细信息。详细信息取自plist
文件。对于这个功能,我使用- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view;
使用this.while我点击特定的annotation
它从Map
提取的位置详细信息为"Pune, Maharashtra, India @ <+18.50565666,+73.85559082> +/- 0.00m"
,它不检查我的plist values.even在给出这些值作为属性在plist中作为每个latlong location.can有人解决我的问题?正在获取所选地图的详细信息来自plist
我的plist文件的详细信息:
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";
}
我的编码:
- (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的fine.but工程上取选定的位置只有它没有working.can人帮助我在哪里有我错在哪里??
在此先感谢。
感谢Rob..i'll现在就来试试吧..上that..i是customAnnotation和item..getting错误 – 2013-02-18 08:36:16
Rob..Confusing可以理解逻辑..但只是在实现它显示错误.. – 2013-02-19 07:15:28
@GreyCode查看https://github.com/robertmryan/MKMapView-custom-annotations的一个工作示例。我从iOS 6.1'MKLocalSearch'中抓取了我的'MKPlacemark'对象,但概念是相同的。 – Rob 2013-02-19 15:35:17