美文网首页
高德导航

高德导航

作者: 小新xin | 来源:发表于2017-07-17 17:23 被阅读69次

    最近看了看高德地图的开发平台以及它们的API,奇怪的是一直没找到语音API,这个问题放到以后再说吧。

    对于高德地图的开发平台,它们提供的说明文档还算健全,而且由于API是国人开发的,所以所有接口都有中文的接口说明,很是容易理解。只不过,在加载它们的第三方库时,总是一个功能一个功能的加载,没有像百度那样,一下子都给了出来(开始我以为我的cocoapods坏了.......)。

    高德开放平台:http://lbs.amap.com/

    做了一个简单的demo,包括地图展示,定位和虚拟导航,具体代码如下:

    首先在AppDelegate里配置了高德开发这的钥匙:

    [objc]view plaincopy

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

    [AMapServicessharedServices].apiKey=@"93c5496bf2b16137226af9170498045b";//这个钥匙key需要去高德开放平台去申请

    returnYES;

    }

    然后在rootviewcontroller的view里边,我添加了两个图层View,一个是地图展示View,另一个是虚拟导航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];// 带逆地理信息的一次定位(返回坐标和地址信息)

    self.locationManager.locationTimeout=2;//   定位超时时间,最低2s,此处设置为2s

    self.locationManager.reGeocodeTimeout=2;//   逆地理请求超时时间,最低2s,此处设置为2s

    self.btn= [[UIButtonalloc]init];

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

    [self.btnsetTitle:@"导航"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=@"方恒国际";

    pointAnnotation.subtitle=@"阜通东大街6号";

    [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;//设置气泡可以弹出,默认为NO

    annotationView.animatesDrop=YES;//设置标注动画显示,默认为NO

    annotationView.draggable=YES;//设置标注可以拖动,默认为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];//开始模拟导航

    }

    #pragma mark - AMapNaviDriveViewDelegate

    @end

    我在最后没有做导航完毕的回调相应,只是想粗略的看一看高德的API。

    其实高德的API都很好理解,就比如下边的行车导航管理器的代理方法:

    每一个回调方法都说明的特别清楚。

    附上两张虚拟导航的截图:

    最后附带一个Podfile文件(包括地图的展示/定位/导航 API):

    [objc]view plaincopy

    target'FairyFishMap'do

    pod'AMap3DMap'

    pod'AMapLocation'

    pod'AMapNavi'

    end

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

    相关文章

      网友评论

          本文标题:高德导航

          本文链接:https://www.haomeiwen.com/subject/dulqkxtx.html