定位

作者: nothing_c | 来源:发表于2016-10-31 19:10 被阅读33次

//需要导入系统动画定位的头文件

#import

//类的扩展(私有的属性.方法)

@interface ViewController() //提示作用

{

//成员变量(自动释放),全局变量在dealloc方法中释放,dealloc方法会在当前类对象的引用计数变成0的时候调用,根视图对象是不会释放掉的,除非切换根视图或者关闭该应用

//定位对象

CLLocationManager *manager;

//地理编码对象(经纬度)

CLGeocoder *_coder;

}

//系统适配屏幕适配图片适配

//Xcode8,对应ios10    Xcode7,对应ios9  Xcode6,对应ios8   Xcode5,对应ios7

//判断定位是否可用(真机可用)

if([CLLocationManager locationServicesEnabled]) {

NSLog(@"---定位可用");

} else {

NSLog(@"+++定位不可用");

}

//定位方式GPS .基站. WiFi,到底用哪个定位,不确定(看苹果公司的定位系统)

manager = [[CLLocationManager alloc] init];

//移动多少距离定位一次(频繁,耗电).精确度越高,越费电

manager.distanceFilter = kCLLocationAccuracyKilometer;

//精确度

manager.desiredAccuracy = 100;

//设置代理

manager.delegate = self;

//开始定位

[manager startUpdatingLocation];

//条件编译,如果当前系统存在这个宏,就编译里面的语句,否则不编译

#ifdef __IPHONE_8_0

//从ios8开始需要请求授权保护用户'隐私'

//当你使用到定位的时候开启点位

[manager requestWhenInUseAuthorization];

//一直打开定位

[manager requestAlwaysAuthorization];

/*

百度地图---下面的'地图开发平台'---ios开发----'定位功能'中可找到

需要在Info.plist文件中对应的添加如下配置:

(1)NSLocationAlwaysUsageDescription

(2)NSLocationWhenInUseUsageDescription

*/

#endif

//模拟器的Debug的Location---Custom Location (经纬度-->百度地图,拾取工具)

//判断朝向

if([CLLocationManager headingAvailable]) {

NSLog(@"朝向服务可用---");

} else {

NSLog(@"朝向不可用");

}

//更新朝向必须真机测试

[manager startUpdatingHeading];

//初始化对象

_coder= [[CLGeocoderalloc]init];

//编码

[_coder geocodeAddressString:@"福建省福州市" completionHandler:^(NSArray *_Nullableplacemarks,NSError*_Nullableerror) {

CLPlacemark *mark = [placemarkslastObject];

CLLocation *loc = mark.location;

CLLocationCoordinate2D coor = loc.coordinate;

CLLocationDegrees lat = coor.latitude;

CLLocationDegrees lon = coor.longitude;

NSLog(@"---%f====%f",lat,lon);

}];

#pragma mark -- CLLocationManagerDelegate

//用户位置发生变化的时候回调用

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray  *)locations__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0) {

//定位只能在国内

CLLocation *loc = [locations lastObject];

//海拔

CLLocationDistance alti = loc.altitude;

//经纬度

CLLocationCoordinate2D coor = loc.coordinate;

//纬度

CLLocationDegrees lat = coor.latitude;

//经度

CLLocationDegrees lon = coor.longitude;

//不是真机alti===0000000

NSLog(@">>>>%f,>>>>>>%f,>>>>>%f",alti,lat,lon);

//这里的location对象需要自己创建

CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:latlongitude:lon];

//反编码

[_coder reverseGeocodeLocation:loc2 completionHandler:^(NSArray  *_Nullableplacemarks,NSError *_Nullableerror) {

//CLPlacemark是位置位置

CLPlacemark *mark = [placemarks lastObject];

NSLog(@"%@",mark.addressDictionary);

//        NSLog(@"3333%@@",error);

}];

//系统地图是高德地图

//火星坐标系(有变差的坐标系);一般大公司有自己地图,用的是火星坐标

//地图的编码和反编码必须用同一套地图

//停止定位

//[manager stopUpdatingLocation];

}

//当用户朝向发生变化的时候调用

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {

//地磁北极不准容易受到磁场的干扰

CLLocationDirection mag = newHeading.magneticHeading;

//地理北极0---359.9 0是北方

CLLocationDirection north = newHeading.trueHeading;

//精确度

CLLocationDirection acc = newHeading.headingAccuracy;

}

相关文章

  • 定位,定位,还是定位

    要想成为一个好的文字的输出者,首先要给自己一个合理的定位。定位可以首先想象自己想成为的角色:一个能够通过各种故事启...

  • 10-CSS定位流

    定位流 定位流分类相对定位绝对定位固定定位静态定位 相对定位 什么是相对定位?相对定位就是相对于自己以前在标准流中...

  • CSS中的几种定位

    CSS中常用的定位有 普通定位,相对定位 绝对定位、fixed定位 浮动 1、普通定位和相对定位 css中的元素有...

  • 2017-02-23 CSS 学习笔记

    定位流 定位流分类 相对定位 绝对定位 固定定位 静态定位 什么是相对定位相对定位就是相对于自己以前在标准中的位置...

  • #30天专注橙长计划#品牌定位30(6)营销推广1

    品牌定位的维度包括: 市场定位、价格定位、形象定位、地理定位、人群定位、渠道定位等; 经过前期大量的市场调研工作,...

  • D28:系统地图, 高德地图

    目录一. 定位功能 iPhone手机定位(基站定位, WiFi定位, GPS定位: 定位所需时间递增, 精确度递增...

  • 相对定位、绝对定位和固定定位

    1. 相对定位 定位有三种:相对定位,绝对定位、固定定位。 相对定位: position:relative lef...

  • 定位流

    定位流指的是:相对定位(relative)/绝对定位(absolute)/固定定位(fixed) 不包括静态定位(...

  • CSS补充2

    定位position 定位分为四种:相对定位 relative,绝对定位 absolute,固定定位 fixed,...

  • 定位

    1、static定位(普通流定位) -------------- 默认定位 2、float定位(浮动定位) 例:f...

网友评论

      本文标题:定位

      本文链接:https://www.haomeiwen.com/subject/nlyputtx.html