高德導(dǎo)航

最近看了看高德地圖的開發(fā)平臺(tái)以及它們的API,奇怪的是一直沒找到語(yǔ)音API,這個(gè)問題放到以后再說吧。

對(duì)于高德地圖的開發(fā)平臺(tái),它們提供的說明文檔還算健全,而且由于API是國(guó)人開發(fā)的,所以所有接口都有中文的接口說明,很是容易理解。只不過,在加載它們的第三方庫(kù)時(shí),總是一個(gè)功能一個(gè)功能的加載,沒有像百度那樣,一下子都給了出來(lái)(開始我以為我的cocoapods壞了.......)。

高德開放平臺(tái):http://lbs.amap.com/

做了一個(gè)簡(jiǎn)單的demo,包括地圖展示,定位和虛擬導(dǎo)航,具體代碼如下:

首先在AppDelegate里配置了高德開發(fā)這的鑰匙:

[objc]view plaincopy

-?(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions?{

[AMapServicessharedServices].apiKey=@"93c5496bf2b16137226af9170498045b";//這個(gè)鑰匙key需要去高德開放平臺(tái)去申請(qǐng)

returnYES;

}

然后在rootviewcontroller的view里邊,我添加了兩個(gè)圖層View,一個(gè)是地圖展示View,另一個(gè)是虛擬導(dǎo)航View

[objc]view plaincopy

//

//??ViewController.m

//??FairyFishMap

//

//??Created?by?jinhui005?on?16/9/19.

//??Copyright???2016年?yhl.?All?rights?reserved.

//

#import?"ViewController.h"

#import?

#import?

#import?

#import?

#import?

@interfaceViewController?()?

@property(nonatomic,strong)MAMapView*mapView;

@property(nonatomic,strong)AMapLocationManager*locationManager;

@property(nonatomic,strong)UIButton*btn;

@property(nonatomic,strong)AMapNaviDriveManager*driveManager;

@property(nonatomic,strong)AMapNaviDriveView*driveView;

@property(nonatomic,strong)AMapNaviPoint*startPoint;

@property(nonatomic,strong)AMapNaviPoint*endPoint;

@end

@implementationViewController

-?(void)viewDidLoad?{

[superviewDidLoad];

self.mapView=?[[MAMapViewalloc]initWithFrame:self.view.frame];

self.mapView.delegate=self;

self.mapView.showsUserLocation=YES;

self.mapView.userTrackingMode=?MAUserTrackingModeFollow;

[self.viewaddSubview:self.mapView];

self.locationManager=?[[AMapLocationManageralloc]init];

self.locationManager.delegate=self;

[self.locationManagerstartUpdatingLocation];

[self.locationManagersetDesiredAccuracy:kCLLocationAccuracyHundredMeters];//?帶逆地理信息的一次定位(返回坐標(biāo)和地址信息)

self.locationManager.locationTimeout=2;//???定位超時(shí)時(shí)間,最低2s,此處設(shè)置為2s

self.locationManager.reGeocodeTimeout=2;//???逆地理請(qǐng)求超時(shí)時(shí)間,最低2s,此處設(shè)置為2s

self.btn=?[[UIButtonalloc]init];

self.btn.frame=?CGRectMake(20,50,90,40);

[self.btnsetTitle:@"導(dǎo)航"forState:UIControlStateNormal];

[self.btnsetTitleColor:[UIColorblueColor]forState:UIControlStateNormal];

[self.btnaddTarget:selfaction:@selector(beginRouting)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:self.btn];

//????[self?showMap];

//????[self?controlEx];

}

-?(void)viewDidAppear:(BOOL)animated?{

[superviewDidAppear:animated];

//????[self?clipOneAnnnotation];

}

-?(void)didReceiveMemoryWarning?{

[superdidReceiveMemoryWarning];

//?Dispose?of?any?resources?that?can?be?recreated.

}

-?(void)showMap?{

self.mapView.showTraffic=NO;

self.mapView.mapType=?MAMapTypeStandard;

}

-?(void)controlEx?{

self.mapView.logoCenter=?CGPointMake(50,450);

self.mapView.showsCompass=NO;

self.mapView.compassOrigin=?CGPointMake(self.mapView.compassOrigin.x,22);

self.mapView.showsScale=NO;

self.mapView.scaleOrigin=?CGPointMake(self.mapView.compassOrigin.x,22);

}

-?(void)clipOneAnnnotation?{

MAPointAnnotation*pointAnnotation?=?[[MAPointAnnotationalloc]init];

pointAnnotation.coordinate=?CLLocationCoordinate2DMake(39.989631,116.481018);

pointAnnotation.title=@"方恒國(guó)際";

pointAnnotation.subtitle=@"阜通東大街6號(hào)";

[self.mapViewaddAnnotation:pointAnnotation];

}

-?(void)beginRouting?{

self.startPoint=?[AMapNaviPointlocationWithLatitude:39.993135longitude:116.474175];

self.endPoint=?[AMapNaviPointlocationWithLatitude:39.908791longitude:116.321257];

self.driveManager=?[[AMapNaviDriveManageralloc]init];

self.driveManager.delegate=self;

self.driveView=?[[AMapNaviDriveViewalloc]init];

self.driveView.frame=self.view.frame;

self.driveView.delegate=self;

[self.viewaddSubview:self.driveView];

[self.driveManageraddDataRepresentative:self.driveView];

[self.driveManagercalculateDriveRouteWithStartPoints:@[self.startPoint]endPoints:@[self.endPoint]wayPoints:nildrivingStrategy:AMapNaviDrivingStrategyDefault];

}

#pragma?mark?-?MAMapViewDelegate

-?(MAAnnotationView*)mapView:(MAMapView*)mapViewviewForAnnotation:(id)annotation

{

if([annotationisKindOfClass:[MAPointAnnotationclass]])

{

staticNSString*pointReuseIndentifier?=@"pointReuseIndentifier";

MAPinAnnotationView*annotationView?=?(MAPinAnnotationView*)[mapViewdequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];

if(annotationView?==nil)

{

annotationView?=?[[MAPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:pointReuseIndentifier];

}

annotationView.canShowCallout=YES;//設(shè)置氣泡可以彈出,默認(rèn)為NO

annotationView.animatesDrop=YES;//設(shè)置標(biāo)注動(dòng)畫顯示,默認(rèn)為NO

annotationView.draggable=YES;//設(shè)置標(biāo)注可以拖動(dòng),默認(rèn)為NO

annotationView.pinColor=?MAPinAnnotationColorPurple;

returnannotationView;

}

returnnil;

}

-?(void)mapView:(MAMapView*)mapViewdidUpdateUserLocation:(MAUserLocation*)userLocationupdatingLocation:(BOOL)updatingLocation?{

}

#pragma?mark?-?AMapLocationManagerDelegate

-?(void)amapLocationManager:(AMapLocationManager*)managerdidUpdateLocation:(CLLocation*)location?{

}

#pragma?mark?-?AMapNaviDriveManagerDelegate

-?(void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager*)driveManager?{

[driveManagerstartEmulatorNavi];//開始模擬導(dǎo)航

}

#pragma?mark?-?AMapNaviDriveViewDelegate

@end

我在最后沒有做導(dǎo)航完畢的回調(diào)相應(yīng),只是想粗略的看一看高德的API。

其實(shí)高德的API都很好理解,就比如下邊的行車導(dǎo)航管理器的代理方法:

每一個(gè)回調(diào)方法都說明的特別清楚。

附上兩張?zhí)摂M導(dǎo)航的截圖:

最后附帶一個(gè)Podfile文件(包括地圖的展示/定位/導(dǎo)航 API):

[objc]view plaincopy

target'FairyFishMap'do

pod'AMap3DMap'

pod'AMapLocation'

pod'AMapNavi'

end



原文地址:http://blog.csdn.net/icefishlily/article/details/52595584

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容