1、添加标注
...
CLLocationCoordinate2D coor;
coor.latitude = 39.915;
coor.longitude = 116.404;
BMKPointAnnotation* annotation = [[BMKPointAnnotationalloc]init];
annotation.coordinate = coor;
annotation.title = @"这里是北京";
[mapView addAnnotation:annotation];//这个行为会触发- (BMKAnnotationView*)mapView: (BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
[self.view addSubview:mapView];
- (BMKAnnotationView*)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
{
BMKPinAnnotationView *animationView = [[BMKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"animation"];
animationView.pinColor = BMKPinAnnotationColorGreen;
animationView.animatesDrop = YES;
return animationView;
}
2、删除标注
if (annotation != nil) {
[_mapView removeAnnotation:annotation];
}
3、添加折线
。。。。。
CLLocationCoordinate2D coors[2] = {0};
coors[0].latitude = 39.315;
coors[0].longitude = 116.304;
coors[1].latitude = 39.515;
coors[1].longitude = 116.504;
BMKPolyline* polyline = [BMKPolyline polylineWithCoordinates:coors count:2];
[mapView addOverlay:polyline]; //触发下面的委托
- (BMKOverlayView*)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay
{
BMKPolylineView *polyine = [[BMKPolylineView alloc]initWithOverlay:overlay];
polyine.strokeColor = [UIColor greenColor];
polyine.lineWidth = 2;
return polyine;
}
4、添加多边形
CLLocationCoordinate2D coors[2] = {0};将这个数组声明大一点就行了比如三角形就三个点。
在回调中通过 polygonView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2]; 进行颜色的填充
5、添加圆
BMKMapView *mapView = [[BMKMapViewalloc]initWithFrame:[[UIScreenmainScreen] bounds]];
mapView.delegate = self;
[mapView setMapType:BMKMapTypeTrafficOn];
CLLocationCoordinate2D coor;
coor.latitude = 39.915;
coor.longitude = 116.404;
BMKCircle *circle = [BMKCirclecircleWithCenterCoordinate:coor radius:5000];
[mapView addOverlay:circle];
//委托
- (BMKOverlayView*)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay
{
if([overlay isKindOfClass:[BMKCircle class]])
{
BMKCircleView* circleView = [[BMKCircleView alloc] initWithOverlay:overlay];
circleView.fillColor = [[UIColorcyanColor] colorWithAlphaComponent:0.5];
circleView.strokeColor = [[UIColorblueColor] colorWithAlphaComponent:0.5];
circleView.lineWidth = 10.0;
return circleView;
}
returnnil;
}