概述

您所在的位置:网站首页 高德桌面插件如何自动定位 概述

概述

2024-07-11 00:12| 来源: 网络整理| 查看: 265

重要:由于个人信息保护法的实施,从定位2.8.0版本起对旧版本SDK不兼容,请务必确保调用SDK任何接口前先调用更新隐私合规updatePrivacyShow、updatePrivacyAgree两个接口,否则可能导致功能不可用等异常情况。具体可参考开发指南-隐私合规说明 传入相关参数。

简介

高德 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。

具体步骤可参看下图

获取 API Key

兼容性

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

给开发者的建议

对于高德开放平台提供的地图API/SDK,若您以非商业目的使用,则均可免费使用 。若您以商业目的使用,则您需事先从高德获取商用授权。您需要先申请Key,才能使用该服务。关于具体使用规则,请参阅《高德地图开放平台服务协议》获得详细信息。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3