一、前奏
这里只是个人集成过程中的遇到的点,现做下标记。
1,如果你需要集成涉及国外版地图,基于HTTPS的最新版本需要设置,需要注意基于国外定位,高德的不太精确(个人测试)
[self.mapView performSelector:@selector(setShowsWorldMap:) withObject:@(YES)];
这个方法后台提供的国外地图是第三方的,是不稳定的,不推荐使用。集成国外版地图详情见:http://lbs.amap.com/dev/demo/switch-map#iOS
2,坐标转换
//将GPS转成高德坐标
CLLocationCoordinate2D amapcoord = MACoordinateConvert(CLLocationCoordinate2DMake(39.989612,116.480972),MACoordinateTypeGPS);
二、实战
1,创建地图
#import
@property (nonatomic, strong)MAMapView *mapView; // 添加属性
// 添加到视图上
_mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
_mapView.delegate = self;
[self.view addSubview:_mapView];
2,设置中心点
CLLocationCoordinate2D centerPoint = CLLocationCoordinate2DMake(30.2740850000,120.1550700000);//纬度,经度
self.mapView.centerCoordinate = centerPoint; // 或者[self.mapView setCenterCoordinate:(centerPoint) animated:YES];
3,隐藏指南针
_mapView.showsCompass = NO;
4,隐藏比例尺
_mapView.showsScale = NO;
5,手势控制
_mapView.zoomEnabled = YES; // NO表示禁用缩放手势,YES表示开启
_mapView.scrollEnabled = YES; // NO表示禁用滑动手势,YES表示开启
6,设置地图语言(默认中文)
_mapView.language = MAMapLanguageEn;
7,添加标注(大头针)
MAPointAnnotation *pointAnnotation1 = [[MAPointAnnotation alloc] init];
pointAnnotation1.coordinate = CLLocationCoordinate2DMake(39.907465,116.337447);
pointAnnotation1.title = @"木樨地";
pointAnnotation1.subtitle = @"北京市西城区复兴门外大街29号楼三里河路";
[_mapView addAnnotation:pointAnnotation]; // 单个添加,多个添加[_mapView addAnnotations:@[pointAnnotation,pointAnnotation1,pointAnnotation2]];
8,自定义标注(大头针)
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation
{
if ([annotation isKindOfClass:[MAPointAnnotation class