首页 > iOS如何在百度地图添加多个标注

iOS如何在百度地图添加多个标注

  - (void) viewDidAppear:(BOOL)animated {
for (int i = 0; i < 3; i++) {
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = 39.915 + i*10;
    coor.longitude = 116.404 + i*10;
    annotation.coordinate = coor;
    annotation.title = @"这里是北京";
     [_mapView   addAnnotation:annotation];   
 }     

}

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
    BMKPinAnnotationView *newAnnotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"AnnotationView"];
    newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"AnnotationView"];
    newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
    newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
    return newAnnotationView;
}
return nil;

}

上面的代码只显示一个标注,如果是调用系统MapKit的库就是显示多个标注,不知道百度地图是如何显示多个标注的。


[_mapView addAnnotation:annotation];

这个用 addAnnotations 方法
先把annotation加到数组里


coor.latitude = 39.915 + i*10;
coor.longitude = 116.404 + i*10;
这里把10改成小数就行了。希望新手有帮助
【热门文章】
【热门文章】