oc 获取经纬度具体位置
来源:互联网 发布:android蓝牙发送数据 编辑:程序博客网 时间:2024/04/27 15:25
1,再 build phases 中的 link binary with libraries 中 导入 CoreLocation.framework 库
2,包含:#import <CoreLocation/CoreLocation.h>
3,特别需要注意的: iPhone 机 需要链接网络, 否则获取的 placemarks is null
4,在info.plist 中添加
<key>NSLocationWhenInUseUsageDescription</key> <string>此App需要您的同意才能访问您的位置</string>
@interface LocationTest : NSObject<CLLocationManagerDelegate>{ CLLocationDegrees lati; CLLocationDegrees longti;}@property(nonatomic,strong)CLLocationManager *locationManager;-(void)InitLocation;
//用户位置获取-(void)InitLocation{ //初始化对象 self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.distanceFilter = 1.0; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {// [self.locationManager requestAlwaysAuthorization]; // 永久授权 [self.locationManager requestWhenInUseAuthorization]; //使用中授权 } [self.locationManager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ NSLog(@"%@", error);}// 代理方法 地理位置反编码- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations { CLLocation *newlocation = locations[0]; CLLocationCoordinate2D oCoordinate = newlocation.coordinate; NSLog(@"经度:%f,维度:%f",oCoordinate.longitude,oCoordinate.latitude); // 给经纬度全局属性赋值 lati = oCoordinate.latitude; longti = oCoordinate.longitude; [self.locationManager stopUpdatingLocation]; CLGeocoder *geocoder = [[CLGeocoder alloc]init]; [geocoder reverseGeocodeLocation:newlocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) { NSLog(@"----------reverseGeocodeLocation---------"); NSString* placeLity = @""; NSString* str = @""; for (CLPlacemark *place in placemarks) { // CLPlacemark* place = placemarks[0]; NSDictionary *location =[place addressDictionary]; NSLog(@"国家:%@",[location objectForKey:@"Country"]); NSLog(@"城市:%@",[location objectForKey:@"State"]); NSLog(@"区:%@",[location objectForKey:@"SubLocality"]); NSLog(@"位置:%@", place.name); NSLog(@"国家:%@", place.country); NSLog(@"城市:%@", place.locality); placeLity = place.locality; NSLog(@"区:%@", place.subLocality); NSLog(@"街道:%@", place.thoroughfare); NSLog(@"子街道:%@", place.subThoroughfare); //字符串拼接 str = [NSString stringWithFormat:@"%@%@%@", place.locality, place.subLocality,place.thoroughfare]; } NSLog(@"----- 位置 %@",str); [LocationTest CallJsLocation:str andLati:lati andLongti:longti]; }]; NSLog(@"=====:%f,%f",lati,longti); }+(void)CallJsLocation:(NSString*)Adree andLati:(float)lati andLongti:(float)longti{ NSLog(@"%@ %f %f",Adree,lati,longti); NSString *func = [NSString stringWithFormat:@"require('jsbScript').responseLocation('%@',%f,%f)",Adree,lati,longti]; // 转为C风格字符串 const char *stringFunc = [func UTF8String]; // OC调用JS ScriptingCore::getInstance()->evalString(stringFunc); }//开启位置+(void)StartLocation{ NSLog(@"---StartLocation----"); //初始化对象 LocationTest* locat = [[LocationTest alloc]init]; [locat InitLocation];}
阅读全文
0 0
- oc 获取经纬度具体位置
- iOS-81-百度地图-通过经纬度获取到具体位置
- Android开发之--利用系统自带的服务获取经纬度并转为具体位置
- OC 源生获取当前位置经纬度
- 获取标签的具体位置的函数
- 用Javascript获取页面元素的具体位置
- 根据ip可以获取到具体位置
- 用Javascript获取页面元素的具体位置
- 获取经纬度
- 获取经纬度
- C# 获取获取经纬度!
- 一个百度定位例子,把自己的经纬度转换为具体位置
- Google Maps获取经纬度
- 获取某地址经纬度
- 精确经纬度的获取
- 获取当前经纬度方法
- Android 如何获取经纬度
- google地图获取经纬度
- 字体小三、小四号字的数字表示是多少
- request和response中的方法使用
- 双11的凌晨,如何证明你是一只程序猿?
- SpringCloud Config 配置中心 svn使用
- Java设计模式(转)
- oc 获取经纬度具体位置
- Running WFSTAT and WFRETRY For Oracle Purchasing Workflows (文档 ID 134960.1)转到底部转到底部 In this Docum
- 利用Retrofit执行Post、Get请求,通俗易懂
- 基于RTP/RTCP的无线视频传输自适应带宽控制
- LeetCode.554 Brick Wall
- ubuntu下github使用指南
- IE6-10浏览器鼠标坐标跟踪安全风险
- 3、新手入手树莓派教程--config
- TOMCAT7并发性能优化总结