ios 持续获取定位 高德地图_概述-iOS 定位SDK | 高德地图API

简介

高德 iOS 定位 SDK 提供了不依赖于地图定位的定位功能,开发者可以无地图显示的场景中便捷地为应用程序添加定位功能。

iOS定位SDK提供了单次定位、连续定位、逆地理信息、地理围栏等功能。

面向的读者

高德地图定位 SDK 是提供给具有一定 iOS 编程经验,了解面向对象编程概念的读者使用的 iOS 移动端 SDK。

功能介绍与体验

抱歉,您的浏览器不支持video标签

抱歉,您的浏览器不支持video标签

抱歉,您的浏览器不支持video标签基础定位

- (void)configLocationManager

{

self.locationManager = [[AMapLocationManager alloc] init];

[self.locationManager setDelegate:self];

[self.locationManager setPausesLocationUpdatesAutomatically:NO];

[self.locationManager setAllowsBackgroundLocationUpdates:YES];

}

- (void)startSerialLocation

{

//开始定位

[self.locationManager startUpdatingLocation];

}

- (void)stopSerialLocation

{

//停止定位

[self.locationManager stopUpdatingLocation];

}

- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error

{

//定位错误

NSLog(@"%s, amapLocationManager = %@, error = %@", __func__, [manager class], error);

}

- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location

{

//定位结果

NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);

}

逆地理编码

- (void)configLocationManager

{

self.locationManager = [[AMapLocationManager alloc] init];

[self.locationManager setDelegate:self];

[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];

[self.locationManager setLocationTimeout:6];

[self.locationManager setReGeocodeTimeout:3];

}

- (void)locateAction

{

//带逆地理的单次定位

[self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {

if (error)

{

NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);

if (error.code == AMapLocationErrorLocateFailed)

{

return;

}

}

//定位信息

NSLog(@"location:%@", location);

//逆地理信息

if (regeocode)

{

NSLog(@"reGeocode:%@", regeocode);

}

}];

}

地理围栏

- (void)configLocationManager

{

self.locationManager = [[AMapLocationManager alloc] init];

[self.locationManager setDelegate:self];

[self.locationManager setPausesLocationUpdatesAutomatically:NO];

[self.locationManager setAllowsBackgroundLocationUpdates:YES];

}

- (void)addCircleReionForCoordinate:(CLLocationCoordinate2D)coordinate

{

int radius = 250;

//创建circleRegion

AMapLocationCircleRegion *cirRegion = [[AMapLocationCircleRegion alloc] initWithCenter:coordinate

radius:radius

identifier:@"circleRegion"];

//添加地理围栏

[self.locationManager startMonitoringForRegion:cirRegion];

//保存地理围栏

[self.regions addObject:cirRegion];

//添加Overlay

MACircle *circle = [MACircle circleWithCenterCoordinate:coordinate radius:radius];

[self.mapView addOverlay:circle];

[self.mapView setVisibleMapRect:circle.boundingMapRect];

}

- (void)amapLocationManager:(AMapLocationManager *)manager didStartMonitoringForRegion:(AMapLocationRegion *)region

{

NSLog(@"开始监听地理围栏:%@", region);

}

- (void)amapLocationManager:(AMapLocationManager *)manager monitoringDidFailForRegion:(AMapLocationRegion *)region withError:(NSError *)error

{

NSLog(@"监听地理围栏失败:%@", error.localizedDescription);

}

- (void)amapLocationManager:(AMapLocationManager *)manager didEnterRegion:(AMapLocationRegion *)region

{

NSLog(@"进入地理围栏:%@", region);

}

- (void)amapLocationManager:(AMapLocationManager *)manager didExitRegion:(AMapLocationRegion *)region

{

NSLog(@"退出地理围栏:%@", region);

}

账号与Key的申请

注册成为高德开发者需要分三步:

第一步,注册高德开发者;

第二步,去控制台创建应用;

第三步,获取Key。

具体步骤可参看下图

兼容性

高德地图 iOS 定位 SDK V2.2.0 之前的版本兼容 iOS 6.0 系统,从 V2.2.0 版本以后从 iOS 7.0 系统开始支持。SDK 内部网络访问全部应用域名访问,不涉及 ipv4 和 ipv6 的问题。

给开发者的建议

高德开放平台提供的地图API/SDK,任何非盈利性网站/应用均可免费使用 。请参阅《高德地图 API 使用条款》获得详细信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值