高德SDK
最近项目中需要定位客户位置,要满足地址搜索,长按地图添加,同时大头针还要能移动的需求,这里整理下,希望帮助有需要的人
1.添加地图
// 地图
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, lineView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-lineView.bottom-kViewMargin)];
_mapView.showsCompass = NO; // 隐藏指南针
_mapView.showsScale = NO; // 隐藏比例尺
_mapView.delegate = self;
[_mapView setUserTrackingMode:MAUserTrackingModeFollow animated:YES]; // 追踪用户位置
[self.view addSubview:_mapView];
2.搜索按钮点击事件
// 搜索按钮事件
- (void)actionSearchAddress:(UIButton *)button
{
[self.view endEditing:YES]; // 结束编辑回收键盘
[[CustomActivityIndicator sharedActivityIndicator] startSynchAnimating];
[_mapView removeAnnotation:_annotation]; // 移除大头针
//构造AMapGeocodeSearchRequest对象,address为必选项,city为可选项
AMapGeocodeSearchRequest *geo = [[AMapGeocodeSearchRequest alloc] init];
geo.address = _searchContentTF.text;
//发起正向地理编码
[_mapSearch AMapGeocodeSearch: geo];
}
3.高德地图代理方法(3.0以上的高德SDK包含点击,长按等地图手势的代理方法)
#pragma mark - MAMapViewDelegate
// 大头针样式
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{
if ([annotation isKindOfClass:[ReGeocodeAnnotation class]])
{
static NSString *pointReuseIndentifier = @"SearchAdressAnnotationView";
MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
if (annotationView == nil)
{
annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
}
annotationView.canShowCallout= YES; //设置气泡可以弹出,默认为NO
annotationView.animatesDrop = YES; //设置标注动画显示,默认为NO
annotationView.draggable = YES; //设置标注可以拖动,默认为NO
annotationView.pinColor = MAPinAnnotationColorPurple;
// 添加点到数值中,便于改变时移除
// if (!_annotationsArray) {
// _annotationsArray = [NSMutableArray array];
// }
// [_annotationsArray addObject:annot