//创建大头针对象
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
//插入大头针的位置
pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.989631, 116.481018);
//大头针的标题
pointAnnotation.title = @"方恒国际";
//大头针的子标题
pointAnnotation.subtitle = @"阜通东大街6号";
[_mapView addAnnotation:pointAnnotation];
//实现下列方法后能让地图上得大头针弹出气泡
- (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; //设置气泡可以弹出,默认为NO
annotationView.animatesDrop = YES; //设置标注动画显示,默认为NO
annotationView.draggable = YES; //设置标注可以拖动,默认为NO
annotationView.pinColor = MAPinAnnotationColorPurple;
return annotationView;
}
return nil;
}
用坐标信息判断 你没说想要的具体的效果 那我就给你说一种吧 假设你地图上面有n个大头针 实际上也就是n个pointAnnotation 你可以通过_mapView.annotations直接获取到 这是个数组
在点击大头针的方法里面
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
{
NSArray * array = [NSArray arrayWithArray:_mapView.annotations];
for (int i=0; i<array.count; i++)
{
if (view.annotation.coordinate.latitude ==((BMKPointAnnotation*)array[i]).coordinate.latitude)
{
//获取到当前的大头针 你可以执行一些操作
}
else
{
//对其余的大头针进行操作 我是删除
//[_mapView removeAnnotation:array[i]];
}
}
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。