iOS开发-- 高德地图的接入使用(2)地图显示

 - (MAMapView *)mapView
{
    if (_mapView == nil) {
        [AMapServices sharedServices].enableHTTPS = YES;// 开启https请求
        _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0,0, Screen_W, Screen_H)];
        _mapView.mapType = MAMapTypeStandard;// 设置地图模式
        _mapView.desiredAccuracy = kCLLocationAccuracyBest;// 设置定位精度
        _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_mapView setZoomLevel:(12.0f) animated:YES];// 设置地图缩放级别
        _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;//是否自定义用户位置精度圈
        _mapView.centerCoordinate = self.mapView.userLocation.coordinate;
        _mapView.pausesLocationUpdatesAutomatically = NO;
        _mapView.showsUserLocation = YES;
        _mapView.delegate = self;  
        _mapView.rotateEnabled = NO;
        _mapView.showTraffic = YES;
        _mapView.showsCompass= NO; // 设置成NO表示关闭指南针;YES表示显示指南针
        _mapView.compassOrigin= CGPointMake(_mapView.compassOrigin.x, Screen_H*0.25 + 10*Size_ratio);
        _mapView.scaleOrigin= CGPointMake(20*Size_ratio, Screen_H*0.25+10*Size_ratio);  //设置比例尺位置
        _mapView.showsScale= NO;  //设置成NO表示不显示比例尺;YES表示显示比例尺`
        _mapView.userTrackingMode = MAUserTrackingModeFollow;
    }
    return _mapView;
}
  • 配置定位权限
    在 Info.plist 文件中增加定位权限配置,如下图示:


  • 值得注意的是,定位权限有三种,您可根据需求进行选择。
1.png
  • 自定义定位小蓝点
//  初始化 MAUserLocationRepresentation 对象
MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
r.showsAccuracyRing = NO;///精度圈是否显示,默认YES
r.showsHeadingIndicator = NO;///是否显示方向指示(MAUserTrackingModeFollowWithHeading模式开启)。默认为YES
r.fillColor = [UIColor redColor];///精度圈 填充颜色, 默认 kAccuracyCircleDefaultColor
r.strokeColor = [UIColor blueColor];///精度圈 边线颜色, 默认 kAccuracyCircleDefaultColor
r.lineWidth = 2;///精度圈 边线宽度,默认0
r.enablePulseAnnimation = NO;///内部蓝色圆点是否使用律动效果, 默认YES
r.locationDotBgColor = [UIColor greenColor];///定位点背景色,不设置默认白色
r.locationDotFillColor = [UIColor grayColor];///定位点蓝色圆点颜色,不设置默认蓝色
r.image = [UIImage imageNamed:@"你的图片"]; ///定位图标, 与蓝色原点互斥
[self.mapView updateUserLocationRepresentation:r];
  • 添加默认的大头针位置
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.989631, 116.481018);
    pointAnnotation.title = @"方恒国际";
    pointAnnotation.subtitle = @"阜通东大街6号";
    [_mapView addAnnotation:pointAnnotation];
  • 实现 <MAMapViewDelegate> 协议中的 mapView:viewForAnnotation:回调函数,设置标注样式。 如下所示
 - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        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;
        return annotationView;
    }
    return nil;
}
下一篇反向地理编码
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容