1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > ios 高德获取定位_概述-iOS 定位SDK | 高德地图API

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

时间:2021-06-08 06:34:04

相关推荐

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 使用条款》获得详细信息。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。