標籤:
1,我們先申請一個appkey,申請appkey必須註冊高德開發人員
2,高德SDK的下載,現在SDK分別有三個庫,根據你的app 裡面的整合需求,可以選擇性的下載添加到自己的工程裡,他們分別是 2D地圖庫,3D地圖庫,還有搜尋庫;
3,添加SDK進自己的項目(工程)裡,添加的時候注意路徑問題,添加完高德SDK之後,我們還需要添加一些系統內建庫,有了這些才能支援高德SDK的運行,他們分別如
4,運行環境的配置,在TARGETS->Build Settings->Other Linker Flaggs 中添加-ObjC。
5,實現地圖
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; [MAMapServices sharedServices].apiKey = @"a2e716827857a145e86e99ea08cfe15f"; _mapView = [[MAMapView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _mapView.mapType = MAMapTypeSatellite;// 設定地圖樣式,衛星 _mapView.showTraffic = YES; // 是否開啟即時交通路況 _mapView.delegate = self; _mapView.logoCenter = CGPointMake(CGRectGetWidth(self.view.bounds)-55, 450);// 設定地圖logo的中心點 _mapView.showsCompass= YES; // 設定成 NO 表示關閉指南針;YES 表示顯示指南針 _mapView.showsScale = YES; // 設定成 NO 表示不顯示比例尺;YES 表示顯示比例尺 _mapView.scaleOrigin= CGPointMake(_mapView.scaleOrigin.x, 22); // 設定比例尺位置 _mapView.compassOrigin= CGPointMake(_mapView.compassOrigin.x, 22); // 設定指南針位置 _mapView.showsUserLocation = YES; // 開啟地圖定位 [_mapView setUserTrackingMode:MAUserTrackingModeFollow animated:YES]; // 設定使用者跟宗模式 }
6,添加標註
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; }- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation{// NSLog("latitude : %f,longitude: %f",userLocation.coordinate.latitude,userLocation.coordinate.l ongitude); NSLog(@"latitude : %f,longitude: %f", userLocation.coordinate.latitude,userLocation.coordinate.longitude); }
7,編碼、反編碼
- (void)viewDidLoad { [super viewDidLoad]; _search = [[AMapSearchAPI alloc] initWithSearchKey:@"a2e716827857a145e86e99ea08cfe15f" Delegate:self]; //初始化搜尋 AMapGeocodeSearchRequest *georequest = [[AMapGeocodeSearchRequest alloc] init]; //構造一個request對象 georequest.searchType = AMapSearchType_Geocode; //設定為地理編碼樣式 georequest.address = @"北大"; //地址 georequest.city = @[@"北京"];//所在城市 [_search AMapGeocodeSearch:georequest]; //發起地理編碼 // Do any additional setup after loading the view, typically from a nib.}#pragma mark 地理編碼成功的回調- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response{ if (response.count == 0) { return; } NSString *string = [NSString stringWithFormat:@"%ld", response.count]; for (AMapTip *tip in response.geocodes) {//response.geocodes所有跟地址匹配的地點 NSLog(@"%@", [NSString stringWithFormat:@"%@", tip.description]); } }
_search = [[AMapSearchAPI alloc] initWithSearchKey:@"a2e716827857a145e86e99ea08cfe15f" Delegate:self]; //初始化搜尋 AMapReGeocodeSearchRequest *georequest = [[AMapReGeocodeSearchRequest alloc] init]; //構造一個request對象 georequest.searchType = AMapSearchType_ReGeocode; //設定為反地理編碼樣式 georequest.location = [AMapGeoPoint locationWithLatitude:39.000 longitude:116.00];//設定所在地裡位置的經緯度 georequest.radius = 1000;//搜尋半徑 georequest.requireExtension = YES;// 是否返回擴充資訊,預設為 NO [_search AMapGeocodeSearch:georequest]; //發起反地理編碼#pragma mark 反地理編碼成功- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{ if (response.regeocode != nil) { //處理搜尋結果 NSString *result = [NSString stringWithFormat:@"%@", response.regeocode]; }}
高德地圖SDK大致使用