我一直在寻找 MKMapview 上自定义标注的解决方案,我不想将图像和文本添加到左侧或右侧附件视图。我想我宁愿创建一个 UIAlertView 来显示选择的映射图钉的所有信息。
我从 JSON 数据中收集了地图图钉上的纬度和经度,该 JSON 数据还包含其他信息,例如:电话号码、网站链接等。
我将如何完成将所有这些信息输入到按下地图图钉时调用的 UIAlertView 中?
这是一些示例代码:
self.result = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if(error == nil)
self.mapLocations = result;
NSLog(@"%@", [result allKeys]);
for (NSDictionary *location in self.mapLocations[@"merchants"]) {
for (NSDictionary *locations in location[@"branches"]) {
NSLog(@"%@",locations);
CLLocationCoordinate2D annotationCoordinate =
CLLocationCoordinate2DMake([locations[@"latitude"] doubleValue],
[locations[@"longitude"] doubleValue]);
Annotation *annotation = [[Annotation alloc] init];
annotation.coordinate = annotationCoordinate;
annotation.title = location[@"name"];
annotation.subtitle = locations[@"street"];
[self.mapView addAnnotation:annotation];
这是我的 MKAnnotationView 方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annoPin"];
MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"annoView"];
if(!view) {
view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annoView"];
}
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:nil action:@selector(showDetails :) forControlEvents:UIControlEventTouchUpInside];
pinView.animatesDrop = YES;
view.rightCalloutAccessoryView = rightButton;
view.image = [UIImage imageNamed:@"check.png"];
view.enabled = YES;
view.canShowCallout = YES;
return view;
}
帮助!