iOS 百度定位(获取经纬度)

由于系统原因,iOS不允许使用第三方定位,因此地图SDK中的定位方法,本质上是对原生定位的二次封装。通过封装,开发者可更便捷的使用。此外,地图SDK中还提供了相应的定位图层(支持定位三态效果),帮助开发者显示当前位置信息。

注:自iOS8起,系统定位功能进行了升级,SDK为了实现最新的适配,自v2.5.0起也做了相应的修改,开发者在使用定位功能之前,需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):

NSLocationWhenInUseUsageDescription ,允许在前台使用时获取GPS的描述

NSLocationAlwaysUsageDescription ,允许永久使用GPS的描述

定位功能可以和地图功能分离使用,单独的定位功能使用方式如下:

首先添加SDK到工程中... ...  
 

添加头文件  
#import <BaiduMapAPI_Location/BMKLocationService.h> 

添加代理  BMKLocationServiceDelegate

-(void)viewDidLoad  

{    

    //初始化BMKLocationService  

    _locService = [[BMKLocationService alloc]init];  

    _locService.delegate = self;  

    //启动LocationService  

    [_locService startUserLocationService];  

}   

//实现相关delegate 处理位置信息更新  

//处理位置坐标更新(秒更新,如果只是需要获取一次,在定位成功后停止定位或把delegate设置成nil)
//停止定位命令如下(
[self.locService stopUserLocationService];) 

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation  

{ 

     //NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);  

}  

//如果只需要获取当前的经纬度 那么下面2条命令可忽略

//处理方向变更信息  

- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation  

{  

    //NSLog(@"heading is %@",userLocation.heading);  

}   

展示定位信息的功能位于“地图和覆盖物”这个功能模块,在使用时要注意选择。核心代码如下:

//以下_mapView为BMKMapView对象  

_mapView.showsUserLocation = YES;//显示定位图层  

[_mapView updateLocationData:userLocation]; 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在iOS开发中获取图片中二维码的定位,可以使用CoreImage框架。具体步骤如下: 1. 使用CIImage加载图片: ``` CIImage *image = [CIImage imageWithCGImage:image.CGImage]; ``` 2. 创建CIDetector并设置识别类型: ``` CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}]; ``` 3. 识别二维码: ``` NSArray *features = [detector featuresInImage:image]; ``` 4. 遍历识别结果,获取二维码定位: ``` for (CIQRCodeFeature *feature in features) { NSArray *corners = feature.corners; // 获取定位四个角的坐标 // 在图像上绘制定位 UIGraphicsBeginImageContext(imageSize); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor); CGContextSetLineWidth(context, 2.0); CGContextMoveToPoint(context, corners[0].x, corners[0].y); CGContextAddLineToPoint(context, corners[1].x, corners[1].y); CGContextAddLineToPoint(context, corners[2].x, corners[2].y); CGContextAddLineToPoint(context, corners[3].x, corners[3].y); CGContextAddLineToPoint(context, corners[0].x, corners[0].y); CGContextStrokePath(context); UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } ``` 这样就可以在原图上绘制出二维码的定位了。需要注意的是,CIDetector只能识别二维码,如果要识别其他类型的码,需要设置不同的detector类型。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值