iOS程序员之高德地图SDK

高德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
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值