当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS LBS地图服务:高德地图定位说明

iOS LBS地图服务:高德地图定位说明

2018年10月08日  | 移动技术网IT编程  | 我要评论

昆明公务员培训,装修 论坛,尖尾兔袋鼠

ios 11出现了四种定位隐私设置 ios 11不能定位问题 ios 11定位隐私选择提示框说明定位原因否则被拒 选择使用应用期间定位屏幕顶部讨厌的蓝色闪烁提示框 如何不出现蓝色定位闪烁提示框 高德地图后台持续定位关键代码

ios 11出现了四种定位隐私设置

这里写图片描述

privacy - location always and when in use usage description
privacy - location always usage description
privacy - location when in use usage description
privacy - location usage description

ios 11不能定位问题

//必须选上,不选上的话,其他三种定位隐私即使设置了也不会出现定位效果
privacy - location always and when in use usage description

log日志会出现如下错误提示

this app has attempted to access privacy-sensitive data without a usage description. 
the app's info.plist must contain both nslocationalwaysandwheninuseusagedescription and nslocationwheninuseusagedescription keys with string values explaining to the user how the app uses this data

这里写图片描述

ios 11定位隐私选择提示框说明定位原因,否则被拒

这里写图片描述

填写定位说明原因的位置

这里写图片描述

效果

这里写图片描述

选择使用应用期间定位–屏幕顶部讨厌的蓝色闪烁提示框

这里写图片描述

这里写图片描述

开启的后台持续定位,这个蓝色的闪烁提示框是ios内部增加的,谁也没办法去掉,除非没有做后台持续定位,在选择使用应用期间,app进入后台就会出现这个蓝色闪烁提示框

这里写图片描述

如何不出现蓝色定位闪烁提示框

1.引导用户选择始终允许定位(始终允许或者不允许的情况下,后台持续定位不会出现蓝色闪烁提示框)

这里写图片描述

2.使用苹果自带的cllocationmanager,修改定位优先级权限

//使用期间定位
- (void)requestwheninuseauthorization api_available(ios(8.0)) api_unavailable(macos);
//始终允许定位
- (void)requestalwaysauthorization api_available(ios(8.0)) api_unavailable(macos) __tvos_prohibited;

去设置默认定位优先级为始终允许定位

3.不做后台持续定位功能!!!!!

高德地图后台持续定位关键代码

这里写图片描述

#import 
#import 
#import 

@interface appdelegate ()
//定位数据管理
@property (nonatomic, strong) amaplocationmanager *locationmanager;
/**
 *  后台定位是否返回逆地理信息,默认no。
 */
@property (nonatomic, assign) bool locatingwithregeocode;
@end
#pragma mark - 后台定位和持续定位。
- (void)initlocation{
    self.locationmanager = [[amaplocationmanager alloc] init];
    self.locationmanager.delegate = self;//遵守代理,实现协议
    //设置定位最小更新距离方法如下,单位米。当两次定位距离满足设置的最小更新距离时,sdk会返回符合要求的定位结果。
    self.locationmanager.distancefilter = 100;

    //开启持续定位
    //ios 9(不包含ios 9) 之前设置允许后台定位参数,保持不会被系统挂起
    [self.locationmanager setpauseslocationupdatesautomatically:no];

    //ios 9(包含ios 9)之后新特性:将允许出现这种场景,同一app中多个locationmanager:一些只能在前台定位,另一些可在后台定位,并可随时禁止其后台定位。
    if ([[[uidevice currentdevice] systemversion] floatvalue] >= 9) {
        self.locationmanager.allowsbackgroundlocationupdates = yes;
    }

    //    如果需要持续定位返回逆地理编码信息
    [self.locationmanager setlocatingwithregeocode:yes];

    //开始持续定位
    [self.locationmanager startupdatinglocation];
}
#pragma mark - 在回调函数中,获取定位坐标,进行业务处理--传递给后台。
- (void)amaplocationmanager:(amaplocationmanager *)manager didupdatelocation:(cllocation *)location regeocode:(amaplocationregeocode *)regeocode{
    nslog(@"location:{纬度lat:%f; 经度lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalaccuracy);
    if (regeocode){
//        nslog(@"regeocode:%@", regeocode);
        [self activitycodewithlocation:location];
    }
}

#pragma mark - 上传经纬度到后台,记录活动轨迹
- (void)activitycodewithlocation:(cllocation *)location{

    nsstring *urlstring = @"api/xxxxx";
    nsdictionary *parameters = @{
                                        @"xposition":[nsstring stringwithformat:@"%f",location.coordinate.longitude],
                                        @"yposition":[nsstring stringwithformat:@"%f",location.coordinate.latitude]
                                        };

    [networktool requestwithtype:requesttypepost urlstring:urlstring parametersauthority:parameters success:^(id  _nullable responseobject) {
       zylog(@"%@",responseobject);
    } failure:^(nserror * _nonnull error) {
        zylog(@"%@",error);
    }];

}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网