</pre><pre name="code" class="objc">
1.将所有坐标标注上
- (void)initAnnotations
{
self.annotations = [NSMutableArray array];
CLLocationCoordinate2D coordinates[10] = {
{39.992520, 116.336170},
{39.992520, 116.336170},
{39.998293, 116.352343},
{40.004087, 116.348904},
{40.001442, 116.353915},
{39.989105, 116.353915},
{39.989098, 116.360200},
{39.998439, 116.360201},
{39.979590, 116.324219},
{39.978234, 116.352792}};
for (int i = 0; i < 10; ++i)
{
MAPointAnnotation *a1 = [[MAPointAnnotation alloc] init];
a1.coordinate = coordinates[i];
a1.title = [NSString stringWithFormat:@"anno: %d", i];
[self.annotations addObject:a1];
}
}
然后会调取 Delegate 方法
#pragma mark - MAMapViewDelegate
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *pointReuseIndetifier = @"pointReuseIndetifier";
MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil)
{
annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
}
annotationView.canShowCallout = YES;
annotationView.animatesDrop = YES;
annotationView.draggable = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.pinColor = [self.annotations indexOfObject:annotation] % 3;
return annotationView;
}
return nil;
}
-----> 添加大头针在地图上
[self.mapView addAnnotations:self.annotations];
---> 跳转到大头针展示的地方
[self.mapView showAnnotations:self.annotations edgePadding:UIEdgeInsetsMake(20, 20, 20, 80) animated:YES];
完成。