ios高德地图定位代码api demo怎么用 ios

iOS第三方地图-高德地图(导航sdk路径规划)_iOS开发_
iOS第三方地图-高德地图(导航sdk路径规划)
来源:人气:2205
高德地图导航sdk的路径规划获取行程信息主要用到AMapNaviManager这个类
然后调下面的方法
@brief 带起点的驾车路径计算
@param startPoints 起点坐标。支持多个起点,起点列表的尾点为实际导航起点,其他坐标点为辅助信息,带有方向性,可有效避免算路到马路的另一侧。
@param endPoints
终点坐标。支持多个终点,终点列表的尾点为实际导航终点,其他坐标点为辅助信息,带有方向性,可有效避免算路到马路的另一侧。
@param wayPoints
途经点坐标序列,同时支持最多3个途经点的路径规划。
@param strategy
驾车路径的计算策略
@return 路径是否计算成功
- (BOOL)calculateDriveRouteWithStartPoints:(NSArray *)startPoints
endPoints:(NSArray *)endPoints
wayPoints:(NSArray *)wayPoints
drivingStrategy:(AMapNaviDrivingStrategy)
成功之后会走AMapNaviManagerDelegate的代理方法
@brief 驾车路径规划成功后的回调函数
- (void)naviManagerOnCalculateRouteSuccess:(AMapNaviManager *)naviM
代理返回的AMapNaviManager就有路径信息
@brief 当前导航路径的信息
@operty (nonatomic, readonly) AMapNaviRoute *naviR
当我们点进去看,找到了。。
@brief 导航路径总长度(单位:米)
@property (nonatomic, assign) int routeL
@brief 导航路径所需的时间(单位:秒)
@property (nonatomic, assign) int routeT
显示终点起点(添加到上面就行了)
创建起点和终点的annitation(起点是定位点的话不创建传入的时候传入坐标就行了)
- (void)addBeginAndEndAnnotation {
_endAnnotation = [[MAPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate = {30.655593,104.073803};
[_endAnnotation setCoordinate:coordinate];
_endAnnotation.title
= @"终点";
[self.mapView addAnnotation:_endAnnotation];
_beginAnnotation = [[MAPointAnnotation alloc] init];
CLLocationCoordinate2D coordinatebegin = {30.612339,104.071503};
[_beginAnnotation setCoordinate:coordinatebegin];
_beginAnnotation.title
= @"起点";
[self.mapView addAnnotation:_beginAnnotation];
会调MAMapViewDelegate中的生成相应的anntation
@brief 根据anntation生成对应的View
@param mapView 地图View
@param annotation 指定的标注
@return 生成的标注View
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id &MAAnnotation&)
绘制路径(得到路径信息绘制)
- (void)showRouteWithNaviRoute:(AMapNaviRoute *)naviRoute
if (naviRoute == nil)
// 清除旧的overlays
if (_polyline)
[self.mapView removeOverlay:_polyline];
self.polyline =
NSUInteger coordianteCount = [naviRoute.routeCoordinates count];
CLLocationCoordinate2D coordinates[coordianteCount];
for (int i = 0; i & coordianteC i++)
AMapNavoint *aCoordinate = [naviRoute.routeCoordinates objectAtIndex:i];
coordinates[i] = CLLocationCoordinate2DMake(aCoordinate.latitude, aCoordinate.longitude);
_polyline = [MAPolyline polylineWithCoordinates:coordinates count:coordianteCount];
[self.mapView addOverlay:_polyline];
&百度云盘demo地址:
优质网站模板最近看了看高德地图的开发平台以及它们的API,奇怪的是一直没找到语音API,这个问题放到以后再说吧。
对于高德地图的开发平台,它们提供的说明文档还算健全,而且由于API是国人开发的,所以所有接口都有中文的接口说明,很是容易理解。只不过,在加载它们的第三方库时,总是一个功能一个功能的加载,没有像百度那样,一下子都给了出来(开始我以为我的cocoapods坏了.......)。
高德开放平台:/
做了一个简单的demo,包括地图展示,定位和虚拟导航,具体代码如下:
首先在AppDelegate里配置了高德开发这的钥匙:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AMapServices sharedServices].apiKey = @&93c38045b&;//这个钥匙key需要去高德开放平台去申请
return YES;
然后在rootviewcontroller的view里边,我添加了两个图层View,一个是地图展示View,另一个是虚拟导航View
ViewController.m
FairyFishMap
Created by jinhui005 on 16/9/19.
Copyright © 2016年 yhl. All rights reserved.
#import &ViewController.h&
#import &MAMapKit/MAMapKit.h&
#import &UIKit/UIKit.h&
#import &AMapFoundationKit/AMapFoundationKit.h&
#import &AMapLocationKit/AMapLocationKit.h&
#import &AMapNaviKit/AMapNaviKit.h&
@interface ViewController () &MAMapViewDelegate, AMapLocationManagerDelegate, AMapNaviDriveManagerDelegate, AMapNaviDriveViewDelegate&
@property (nonatomic, strong) MAMapView *mapV
@property (nonatomic, strong) AMapLocationManager *locationM
@property (nonatomic, strong) UIButton *
@property (nonatomic, strong) AMapNaviDriveManager *driveM
@property (nonatomic, strong) AMapNaviDriveView *driveV
@property (nonatomic, strong) AMapNaviPoint *startP
@property (nonatomic, strong) AMapNaviPoint *endP
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[MAMapView alloc] initWithFrame:self.view.frame];
self.mapView.delegate =
self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MAUserTrackingModeF
[self.view addSubview:self.mapView];
self.locationManager = [[AMapLocationManager alloc] init];
self.locationManager.delegate =
[self.locationManager startUpdatingLocation];
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
// 带逆地理信息的一次定位(返回坐标和地址信息)
self.locationManager.locationTimeout =2;
定位超时时间,最低2s,此处设置为2s
self.locationManager.reGeocodeTimeout = 2;
逆地理请求超时时间,最低2s,此处设置为2s
self.btn = [[UIButton alloc] init];
self.btn.frame = CGRectMake(20, 50, 90, 40);
[self.btn setTitle:@&导航& forState:UIControlStateNormal];
[self.btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.btn addTarget:self action:@selector(beginRouting) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btn];
[self showMap];
[self controlEx];
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self clipOneAnnnotation];
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void)showMap {
self.mapView.showTraffic = NO;
self.mapView.mapType = MAMapTypeS
- (void)controlEx {
self.mapView.logoCenter = CGPointMake(50, 450);
self.mapView.showsCompass = NO;
passOrigin = CGPointMake(passOrigin.x, 22);
self.mapView.showsScale = NO;
self.mapView.scaleOrigin = CGPointMake(passOrigin.x, 22);
- (void)clipOneAnnnotation {
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.6.481018);
pointAnnotation.title = @&方恒国际&;
pointAnnotation.subtitle = @&阜通东大街6号&;
[self.mapView addAnnotation:pointAnnotation];
- (void)beginRouting {
self.startPoint = [AMapNaviPoint locationWithLatitude:39.993135 longitude:116.474175];
self.endPoint
= [AMapNaviPoint locationWithLatitude:39.908791 longitude:116.321257];
self.driveManager = [[AMapNaviDriveManager alloc] init];
self.driveManager.delegate =
self.driveView = [[AMapNaviDriveView alloc] init];
self.driveView.frame = self.view.
self.driveView.delegate =
[self.view addSubview:self.driveView];
[self.driveManager addDataRepresentative:self.driveView];
[self.driveManager calculateDriveRouteWithStartPoints:@[self.startPoint] endPoints:@[self.endPoint] wayPoints:nil drivingStrategy:AMapNaviDrivingStrategyDefault];
#pragma mark - MAMapViewDelegate
- (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 = MAPinAnnotationColorP
return annotationV
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation {
#pragma mark - AMapLocationManagerDelegate
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location {
#pragma mark - AMapNaviDriveManagerDelegate
- (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager {
[driveManager startEmulatorNavi];//开始模拟导航
#pragma mark - AMapNaviDriveViewDelegate
我在最后没有做导航完毕的回调相应,只是想粗略的看一看高德的API。
其实高德的API都很好理解,就比如下边的行车导航管理器的代理方法:
每一个回调方法都说明的特别清楚。
附上两张虚拟导航的截图:
最后附带一个Podfile文件(包括地图的展示/定位/导航 API):
target 'FairyFishMap' do
pod 'AMap3DMap'
pod 'AMapLocation'
pod 'AMapNavi'
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2606次
排名:千里之外
原创:24篇
(3)(2)(17)(1)(1)(4)iOS 地图SDK | 高德开放平台 | 高德地图API 附近派单功能
iOS 地图SDK | 高德开放平台 | 高德地图API 附近派单功能
您现在的位置: &
& 附近派单功能
附近派单功能
高德地图 iOS SDK V3.0.0 搜索包提供了附近派单功能。
1.什么是附近功能?
附近派单功能是面向中小型O2O企业的一整套功能接口。iOS和Android端均支持这个功能,是连接前端SDK产品和云图的中间功能。
2.附近能够做什么?
(1)O2O开发者通过附近功能提供的用户数据排名结果结合自有业务逻辑,更精准的把控业务订单派发和资源调度。
(2)O2O使用者通过附近功能找正在使用该应用的用户列表,找朋友、找客户等等。
3.附近应用在哪些场景?
(1)根据距离排名,合理的推荐上门美甲服务的接单美甲师。
(2)根据行车距离排名,推荐最近的货车司机师傅接单。
(3)周围和我使用同一个app的用户。
4.使用附近派单功能的流程
第一步、注册附近功能
在使用附近之前,需要对应用的密钥(Key)做相应的注册操作。支持多个移动端app做位置信息上传,及一个或多个app、或服务端之间实现位置信息排名的查看功能。
第二步、集成SDK
附近功能是iOS SDK搜索库提供的一个功能模块,需在官网下载包含附近功能的SDK,并将其集成到自己的开发环境中即可。
第三步、开发
完成附近功能的注册和SDK集成后,即可开始具体功能的开发工作,如需在服务端检索距离排名请参考后文云图检索服务部分的详细介绍。
注册附近功能
注册附近是使用其相应功能的基础前提。通过注册可实现一个或多个应用之间的关系绑定,实现后续的位置数据排名空间检索。
构造附近管理对象
在使用位置信息上传之前,需要构造附近管理对象。
示例代码如下:
1234567891011121314@interface NearbyVewController ()&amapnearbysearchmanagerdelegate&{&&&&AMapNearbySearchManager *_nearbyM}- (void)viewDidLoad {&&&&[super viewDidLoad];&&&&// Do any additional setup after loading the view, typically from a nib.&&&&_nearbyManager = [AMapNearbySearchManager sharedInstance];&&&&_nearbyManager.delegate =}&/amapnearbysearchmanagerdelegate&
附近功能支持单次上传和连续上传信息两种模式,以满足不同的用户场景。AMapNearbyUploadInfo 对象来存储上传数据,包括:坐标系类型、用户位置信息和用户业务逻辑id。
单次上传的示例代码如下:
1234567891011121314//构造上传数据对象AMapNearbyUploadInfo *info = [[AMapNearbyUploadInfo alloc] init];info.userID = @"1";//业务逻辑idinfo.coordinateType = AMapSearchCoodinateTypeAM//坐标系类型info.coordinate = CLLocationCoordinate2DMake(39, 114);//用户位置信息if ([_nearbyManager uploadNearbyInfo:info]){&&&&NSLog(@"YES");}else{&&&&NSLog(@"NO");}
开始连续自动上传,需实现 &AMapNearbySearchManagerDelegate& 协议中的 nearbyInfoForUploading 回调。示例代码如下:
1234567891011121314151617if (_nearbyManager.isAutoUploading){&&&&[_nearbyManager stopAutoUploadNearbyInfo];//关闭自动上传}else{&&&&[_nearbyManager startAutoUploadNearbyInfo];//开启自动上传}- (AMapNearbyUploadInfo *)nearbyInfoForUploading:(AMapNearbySearchManager *)manager{&&&&AMapNearbyUploadInfo *info = [[AMapNearbyUploadInfo alloc] init];&&&&info.userID = kUserID;&&&&info.coordinate = CLLocationCoordinate2DMake(39.004, 114.003);&&&&&&&&&return }
附近位置检索
附近功能还提供从上传的用户信息中,检索附近的用户的能力。检索过程支持距离、时间等约束条件;返回结果支持按照距离由近及远的排序。
同样,附近位置检索,我们也提供两种方式,详细介绍如下:
通过搜索SDK
同其他搜索服务的方法相同,包括一下4步:
1.构造主搜索对象 AMapSearchAPI;
2.配置检索参数 AMapNearbySearchRequest ;
3.发起附近搜索 AMapNearbySearch:;
4.最后在相应的回调函数 onNearbySearchDone:response:中解析数据。
核心代码如下(主搜索对象AMapSearchAPI构造可参考其他的搜索功能,详见:中的描述。):
12345678910111213141516171819202122232425262728//构造AMapNearbySearchRequest对象,配置周边搜索参数AMapNearbySearchRequest *request = [[AMapNearbySearchRequest alloc] init];request.center = [AMapGeoPoint locationWithLatitude:39.001 longitude:114.002];//中心点request.radius = 10000;//搜索半径request.timeRange = 10000;//查询的时间request.searchType = AMapNearbySearchTypeD//驾车距离,AMapNearbySearchTypeLiner表示直线距离//发起附近周边搜索 [_search AMapNearbySearch:request];//附近周边搜索回调- (void)onNearbySearchDone:(AMapNearbySearchRequest *)request response:(AMapNearbySearchResponse *)response{&&& &&&&if(s.count == 0)&&&&{&&&&&&&&return;&&&&}&&&&for (AMapNearbyUserInfo *info s)&&&&{&&&&&&&&MAPointAnnotation *anno = [[MAPointAnnotation alloc] init];&&&&&&&&anno.title = info.userID;&&&&&&&&anno.subtitle = [[NSDate dateWithTimeIntervalSince1970:info.updatetime] descriptionWithLocale:[NSLocale currentLocale]];&&&&&&&&&&&&&&&&&anno.coordinate = CLLocationCoordinate2DMake(info.location.latitude, info.location.longitude);&&&&&&&&&&&&&&&&&[_mapView addAnnotation:anno];&&&&}}
通过云图检索服务
通过请求串可以在业务逻辑服务中使用高德空间检索的能力对自有数据进行检索,获取按照距离、时间等维度约束的附近用户位置信息排序结果,详细内容请移步至查看。
清除用户信息
用户信息清除后,将不会再被检索到,比如接单的美甲师下班后可以清除其位置信息。
清除信息的核心代码如下:
1[_nearbyManager clearUserInfoWithID:@"d2"];
清除用户信息后,会触发 onUserInfoClearedWithError: 回调,检查是否清除成功。核心代码如下:
1234567891011- (void)onUserInfoClearedWithError:(NSError *)error{&&&&if (error)&&&&{&&&&&&&&NSLog(@"clear error: %@", error);&&&&}&&&&else&&&&{&&&&&&&&NSLog(@"clear OK");&&&&}}
发表评论:
馆藏&21031
TA的最新馆藏[转]&高德地图API推出室内地图SDK
发表于 10:48|
作者耿立影
摘要:刚刚在2014年初推出便捷高效的云存储产品云图不久,高德LBS开放平台马不停蹄的在近日又推出了室内地图SDK和静态图API,继续丰富其为海量移动应用所提供的位置服务。
刚刚在2014年初推出便捷高效的云存储产品云图不久,高德LBS开放平台马不停蹄的在近日又推出了室内地图SDK和静态图API,继续丰富其为海量移动应用所提供的位置服务。
作为针对建筑物内部场景的地图开发包,室内地图SDK对高德移动端SDK应用场景进行了更大范围的扩展。该产品发布Android、iOS两个版本,可提供室内场景浏览、楼层切换、室内外地图切换等功能。对于配备室内地图的应用,用户不仅可以在室外就了解到建筑物内的布局和内容,也可以在室内更快捷的找到ATM机、卫生间、电梯等设施,提供更细致的服务。
在功能上,室内地图SDK支持室内地图与室外地图的切换,地图对接,查找路线更便利。此外其支持国内几千个建筑的室内地图,不仅包括商场,还有医院、汽车站、博物馆等,对应应用范围更广。
高德室内地图
除室内地图SDK外,高德地图API还同时上线了静态图API,其通过返回一张地图图片响应HTTP请求,使开发者能够将高德地图以图片形式嵌入自己的网页中。开发者可以指定请求的地图位置,以及在地图上添加如标签、标注、折线、多边形等指引和提示。
静态地图API在宜搜、一搜等手机搜索引擎上十分方便,用户在搜索地址时可直接看到地图显示,而在微博等社交平台上进行地址标注和位置分享等,也会令所在位置一目了然。
静态图在微博上的应用
在这两款新产品之前,高德地图API已经相继推出了Javascript API,Android、iOS、Windows Phone、Windows
8平台的SDK,以及Android平台上的定位SDK和街景SDK。据透露,高德API服务调用量在2013年全年增长5.6倍,而高德API月活跃APP数也在全年增长4.3倍,发展十分迅速。此外,高德LBS开放平台已向30万开发者开放地图API服务。
推荐阅读相关主题:
CSDN官方微信
扫描二维码,向CSDN吐槽
微信号:CSDNnews
相关热门文章百度map api 高德地图api google map api 哪个在ios上用更合适更全面
- 移动改变生活!
百度map api 高德地图api google map api 哪个在ios上用更合适更全面
百度map api 高德地图api 哪个在ios上用更合适 更全面 更稳定
不区分大小写
百度和高德地图只能是国内的。百度的POI信息多一点,其余方面,二者真是差不多
略懂社热议
等待您来回答
该问题来自:
<移动开发社区
手机领域专家
&SOGOU - 京ICP证050897号

我要回帖

更多关于 ios高德地图sdk 的文章

 

随机推荐