地图,怎样把jpg转为矢量图CLLocationCoordinate2D转为CLLocation

地图定位CLLocation详解 - CSDN博客
地图定位CLLocation详解
1.CLLocation主要有一下几个重要的属性
&& & *& CLLocation
&& & *& coordinate :
&& & *& altitude :
&& & *& course : 航向
&& & *& 速度
1.1&distanceFromLocation: 方法
distanceFromLocation:
Discussion:
Returns the lateral distance between two locations.
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_3_2);
可以这样一小段代码计算
CLLocation *l1 = [[CLLocation alloc] initWithLatitude:21.123 longitude:123.456];
CLLocation *l2 = [[CLLocation alloc] initWithLatitude:22.123 longitude:123.456];
CLLocationDistance distance = [l1 distanceFromLocation:l2];
NSLog(@&distance=%f&, distance);
[] distance=969
2.course :航向
&& & *& 场景演示:打印当前用户的行走方向,偏离角度以及对应的行走距离,
& & & & 例如:”北偏东 30度&方向,移动了8米”
&pre name=&code& class=&objc&&#import &ViewController.h&
#import &CoreLocation/CoreLocation.h&
@interface ViewController ()&CLLocationManagerDelegate&
CLLocation *_oldL;
/** 位置管理者 */
@property (nonatomic, strong) CLLocationManager *lM;
@implementation ViewController
#pragma mark - 懒加载
- (CLLocationManager *)lM
if (!_lM) {
// 1. 创建位置管理者
_lM = [[CLLocationManager alloc] init];
// 1.1 代理, 通知, block
_lM.delegate =
// 每隔多米定位一次
_lM.distanceFilter = 100;
kCLLocationAccuracyBestForNavigation // 最适合导航
kCLLocationAccuracyB // 最好的
kCLLocationAccuracyNearestTenM // 10m
kCLLocationAccuracyHundredM // 100m
kCLLocationAccuracyK // 1000m
kCLLocationAccuracyThreeK // 3000m
// 精确度越高, 越耗电, 定位时间越长
_lM.desiredAccuracy = kCLLocationAccuracyB
/** -------iOS8.0+定位适配-------- */
if([[UIDevice currentDevice].systemVersion floatValue] &= 8.0)
// 前台定位授权(默认情况下,不可以在后台获取位置, 勾选后台模式 location update, 但是 会出现蓝条)
[_lM requestWhenInUseAuthorization];
// 前后台定位授权(请求永久授权)
// +authorizationStatus != kCLAuthorizationStatusNotDetermined
// 这个方法不会有效
// 当前的授权状态为前台授权时,此方法也会有效
[_lM requestAlwaysAuthorization];
// 允许后台获取用户位置(iOS9.0)
if([[UIDevice currentDevice].systemVersion floatValue] &= 9.0)
// 一定要勾选后台模式 location updates
_lM.allowsBackgroundLocationUpdates = YES;
if ([_lM respondsToSelector:@selector(requestAlwaysAuthorization)])
[_lM requestAlwaysAuthorization];
return _lM;
-(void)touchesBegan:(NSSet&UITouch *& *)touches withEvent:(UIEvent *)event
[self.lM startUpdatingLocation];
CLLocation *l1 = [[CLLocation alloc] initWithLatitude:21.123 longitude:123.456];
CLLocation *l2 = [[CLLocation alloc] initWithLatitude:22.123 longitude:123.456];
CLLocationDistance distance = [l1 distanceFromLocation:l2];
NSLog(@&distance=%f&, distance);
#pragma mark - CLLocationManagerDelegate
更新到位置之后调用
@param manager
位置管理者
@param locations 位置数组
* is kind of
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray&CLLocation *& *)locations
NSLog(@&定位到了&);
CLLocation 详解
coordinate : 经纬度
altitude : 海拔
course : 航向
CLLocation *location = [locations lastObject];
NSLog(@&%@&, location);
场景演示:打印当前用户的行走方向,偏离角度以及对应的行走距离,
例如:”北偏东 30度
方向,移动了8米”
// 1. 获取方向偏向
NSString *angleStr =
switch ((int)location.course / 90) {
angleStr = @&北偏东&;
angleStr = @&东偏南&;
angleStr = @&南偏西&;
angleStr = @&西偏北&;
angleStr = @&跑沟里去了!!&;
// 2. 偏向角度
NSInteger angle = 0;
angle = (int)location.course % 90;
// 代表正方向
if (angle == 0) {
NSRange range = NSMakeRange(0, 1);
angleStr = [NSString stringWithFormat:@&正%@&, [angleStr substringWithRange:range]];
// 3.移动多少米
double distance = 0;
distance = [location distanceFromLocation:_oldL];
// 4. 拼串 打印
// 例如:”北偏东 30度
方向,移动了8米”
NSString *noticeStr = [NSString stringWithFormat:@&%@%zd方向, 移动了%f米&, angleStr, angle, distance];
NSLog(@&%@&, noticeStr);
授权状态发生改变时调用
@param manager 位置管理者
@param status
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
switch (status) {
// 用户还未决定
case kCLAuthorizationStatusNotDetermined:
NSLog(@&用户还未决定&);
case kCLAuthorizationStatusRestricted:
NSLog(@&访问受限&);
// 定位关闭时和对此APP授权为never时调用
case kCLAuthorizationStatusDenied:
// 定位是否可用(是否支持定位或者定位是否开启)
if([CLLocationManager locationServicesEnabled])
NSLog(@&定位开启,但被拒&);
NSLog(@&定位关闭,不可用&);
NSLog(@&被拒&);
// 获取前后台定位授权
case kCLAuthorizationStatusAuthorizedAlways:
case kCLAuthorizationStatusAuthorized: // 失效,不建议使用
NSLog(@&获取前后台定位授权&);
// 获得前台定位授权
case kCLAuthorizationStatusAuthorizedWhenInUse:
NSLog(@&获得前台定位授权&);
// 定位失败
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
NSLog(@&定位失败&);
3.1.磁北角度
4.区域监听
#import &ViewController.h&
#import &CoreLocation/CoreLocation.h&
@interface ViewController ()&CLLocationManagerDelegate&
位置管理者 */
@property (nonatomic, strong) CLLocationManager *lM;
@implementation ViewController
- (CLLocationManager *)lM
if (!_lM) {
_lM = [[CLLocationManager alloc] init];
_lM.delegate =
//请求用户定位授权
if([[UIDevice currentDevice].systemVersion floatValue] &= 8.0)
[_lM requestAlwaysAuthorization];
return _lM;
- (void)touchesBegan:(NSSet&UITouch *& *)touches withEvent:(UIEvent *)event
// 区域监听
CLLocationCoordinate2D center = {21.13, 123.456};
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:1000 identifier:@&walden&];
[self.lM startMonitoringForRegion:region];
CLLocationCoordinate2D center2 = {21.13, 123.456};
CLCircularRegion *region2 = [[CLCircularRegion alloc] initWithCenter:center2 radius:1000 identifier:@&walden&];
[self.lM startMonitoringForRegion:region2];
// 请求区域状态
[self.lM requestStateForRegion:region];
#pragma mark - CLLocationManagerDelegate
// 进入区域
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
NSLog(@&进入区域--%@&, region.identifier);
// 离开区域
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
NSLog(@&离开区域--%@&, region.identifier);
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
NSLog(@&%zd&, state); //这个state是个枚举值
* CLRegionState
* Discussion:
Represents the current state of the device with reference to a region.
typedef NS_ENUM(NSInteger, CLRegionState){
CLRegionStateUnknown,
CLRegionStateInside,
CLRegionStateOutside
} NS_ENUM_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED __WATCHOS_PROHIBITED;
5.地理编码与反地理编码
#import &ViewController.h&
#import &CoreLocation/CoreLocation.h&
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *addressTV;
@property (weak, nonatomic) IBOutlet UITextField *laTF;
@property (weak, nonatomic) IBOutlet UITextField *longTF;
/** 地理编码 */
@property (nonatomic, strong) CLGeocoder *geoC;
@implementation ViewController
- (CLGeocoder *)geoC
if (!_geoC) {
_geoC = [[CLGeocoder alloc] init];
return _geoC;
- (IBAction)geoCoder {
NSString *addr
= self.addressTV.
if ([addr length] == 0) {
[self.geoC geocodeAddressString:@&重庆& completionHandler:^(NSArray&CLPlacemark *& * _Nullable placemarks, NSError * _Nullable error) {
CLPlacemark
location : 位置对象
addressDictionary : 地址字典
name : 地址全称
if(error == nil)
NSLog(@&%@&, placemarks);
[placemarks enumerateObjectsUsingBlock:^(CLPlacemark * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@&%@&, obj.name);
self.addressTV.text = obj.
self.laTF.text = @(obj.location.coordinate.latitude).stringV
self.longTF.text = @(obj.location.coordinate.longitude).stringV
NSLog(@&cuowu--%@&, error.localizedDescription);
- (IBAction)reverseGeoCoder {
double lati = [self.laTF.text doubleValue];
double longi = [self.longTF.text doubleValue];
// TODO: 容错
CLLocation *loc = [[CLLocation alloc] initWithLatitude:lati longitude:longi];
[self.geoC reverseGeocodeLocation:loc completionHandler:^(NSArray&CLPlacemark *& * _Nullable placemarks, NSError * _Nullable error) {
if(error == nil)
NSLog(@&%@&, placemarks);
[placemarks enumerateObjectsUsingBlock:^(CLPlacemark * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@&%@&, obj.name);
self.addressTV.text = obj.
self.laTF.text = @(obj.location.coordinate.latitude).stringV
self.longTF.text = @(obj.location.coordinate.longitude).stringV
NSLog(@&cuowu&);
6.&INTULocationManager框架的使用
#import &ViewController.h&
#import &INTULocationManager.h&
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)touchesBegan:(NSSet&UITouch *& *)touches withEvent:(UIEvent *)event
#warning 注意要在info.plist中配置请求用户隐私权限的key
//精确度 超时
是否一直获取位置信息
INTULocationManager *locMgr = [INTULocationManager sharedInstance];
INTULocationRequestID requestID =
[locMgr requestLocationWithDesiredAccuracy:INTULocationAccuracyCity
timeout:5.0
delayUntilAuthorized:YES
block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
if (status == INTULocationStatusSuccess) {
NSLog(@&%@&, currentLocation);
NSLog(@&cuowu--%zd&, status);
INTULocationManager *locMgr = [INTULocationManager sharedInstance];
INTULocationRequestID requestID =
[locMgr subscribeToLocationUpdatesWithBlock:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
if (status == INTULocationStatusSuccess) {
NSLog(@&%@&, currentLocation);
NSLog(@&cuowu--%zd&, status);
// Force the request to complete early, like a manual timeout (will execute the block)
[[INTULocationManager sharedInstance] forceCompleteLocationRequest:requestID];
// Cancel the request (won't execute the block)
[[INTULocationManager sharedInstance] cancelLocationRequest:requestID];
本文已收录于以下专栏:
相关文章推荐
有关苹果官方用语定位之后描述一个点的所有属性的信息的一切内容。
1、//新的方法,登陆成功之后(旧的方法就不管了)
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocatio...
定位服务 CLLocationManager 的简单用法一、在开始写这个博客之前(下面先介绍完再写代码),我首先从“万物皆对象”的角度 和 用户的角度来 描述一下个人理解的面向对象编程思想,并且用它来...
1:CLLocationDegrees 经纬度
CLLocationDegrees latitude = theLocation.coordinate.
CLLocationCo...
获取用户当前所在位置的经纬度。
二、实现过程
拟采用CLLocationManager类获取用户位置信息,所需步骤
1、导入CoreLocation.frameWork
对于在测试阶段的APP,大多数都选择使用移动开发者服务平台的SMSSDK,这套框架很实用,可以较为快速和稳定地将短信验证功能实现到项目工程中
第一步 下载SMSSDK
地址为 ht...
一、简单说明
1.CLLocationManager
CLLocationManager的常用操作和属性
开始用户定位- (void)startUpdatingL
停止用户...
现在的物流APP,团购App很多都需要使用到定位功能,怎么才能用最少的时间与精力搞定定位功能呢,其实我也没有什么经验,只是把我的demo分享一下,系统自带的
帮助了我们不少...
Android高效率编码-第三方SDK详解系列(一)——百度地图,绘制,定位,这里都有这是一个系列,但是我也不确定具体会更新多少期,最近很忙,主要还是效率的问题,所以一些有效的东西还是会及时更新的,比...
LBS: location Based Service (基于定位服务)位置服务
要实现地图、导航功能,首先要熟悉定位功能,苹果提供给咱们 CoreLocation 框架进行定位CoreLocatio...
他的最新文章
讲师:王禹华
讲师:宋宝华
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)ios - How to store CLLocationCoordinate2D? - Stack Overflow
Learn, Share, Build
Each month, over 50 million developers come to Stack Overflow to learn, share their knowledge, and build their careers.
Join the world’s largest developer community.
Display name
Email address
By registering, you agree to the
I'm attempting to build an application that builds and saves routes similar to map my run. I'm using the
sample code, specifically the CrumbPath and CrumbPathView as the base of my routes, from Apple. Two questions:
If I try to access the MKMapPoint *points object of the CrumbPath like so:
[_route lockForReading];
NSLog(@"%@", _route.points);
NSLog(@"%d", _route.pointCount);
[_route unlockForReading];
my app crashes, saying:
Thread 1: EXC_BAD_ACCESS (code: 1, address: 0x9450342d)
Which I have a hard time understanding, because within the CrumbPath.m file, the folks at apple write to the "array" by explicitly acquiring the write lock, and then unlocking it, but if I acquire the read lock and attempt to read from it, it crashes.
The reason I attempt to access the points is in an attempt to get the MKMapPoints, convert them to CLLocationCoordinate2D objects, and save them so I can redraw the polyline at the user's request. Since I cannot get access to the points, I attempt to save the CLLocationCoordinate2D objects from my locationManager that I send to the _route in an array to upload to my
backend, but I always get an error saying:
Sending 'CLLocationCoordinate2D' to parameter of incompatible type 'id'
Which isn't making this any easier. Does anybody have any insight to why I'm getting these errors?
Location Manager Delegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
if (_userLocation.longitude != manager.location.coordinate.longitude
&& _userLocation.latitude != manager.location.coordinate.latitude) {
_userLocation = manager.location.
if (_isRecording) {
if (!_route) {
NSLog(@"lat: %f, lng: %f", _userLocation.latitude, _userLocation.longitude);
_route = [[CrumbPath alloc] initWithCenterCoordinate:_userLocation];
[_mapView addOverlay:_route];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(_userLocation, );
[_mapView setRegion:region animated:YES];
MKMapRect updateRect = [_route addCoordinate:_userLocation];
if (!MKMapRectIsNull(updateRect)) {
MKZoomScale currentZoomScale = (CGFloat)(_mapView.bounds.size.width / _mapView.visibleMapRect.size.width);
CGFloat lineWidth = MKRoadWidthAtZoomScale(currentZoomScale);
updateRect = MKMapRectInset(updateRect, -lineWidth, -lineWidth);
[_routeView setNeedsDisplayInMapRect:updateRect];
[_routePoints addObject:_userLocation];
[_route lockForReading];
NSLog(@"%d", _route.pointCount);
NSLog(@"%@", _route.points);
[_route unlockForReading];
Stop Recording Logic
//stop recording
NSLog(@"STOP");
if (_route) {
NSLog(@"There is a route");
//Show route options toolbar
[_route lockForReading];
NSLog(@"%@", _route);
NSLog(@"%d", _route.pointCount);
NSLog(@"%@", _route.points);
PFObject *routeToSave = [PFObject objectWithClassName:@"Routes"];
//[routeToSave setObject:_route forKey:@"routePoints"];
[_route unlockForReading];
[routeToSave saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"%c", succeeded);
NSLog(@"%@", error);
3,28621830
Regarding your first issue, the crash was because of this:
NSLog(@"%@", _route.pointCount);
It should be:
NSLog(@"%d", _route.pointCount);
As mentioned in my comments, %d should be used for count and %@ will cause a crash.
Regarding your second issue, you cannot add a c struct to an NSArray. You should wrap it in NSValue before adding it to an array. CLLocationCoordinate2D is a c-struct. Check the
Change this:
[_routePoints addObject:_userLocation];
NSValue *aValue = [NSValue valueWithMKCoordinate:_userLocation];
[_routePoints addObject:aValue];
To get the coordinate back from NSValue, you can use,
[aValue MKCoordinateValue];
As mentioned in your error message, you were trying to add CLLocationCoordinate2D to an array which expects an object.
21.9k55181
Whatever api you're using to talk to parse is expecting an id which is a pointer to any object. A cllocationcoordinate2d is a c-struct of two doubles and not an object if I'm not mistaken. You should probably create a little wrapper object to save those two doubles and convert them to/from CLLocationCoordinate2d items.
1,49941729
Line: NSLog(@"%@", _route.points); is wrong
_route.points is not a String, and you are using the NSStrig formating symbol "%@".
Since CLLocationCoordinate2D is a C-Sruct and not an Objective-C Object, you probaly want to create an own GeoPoint class.
23.7k53567
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 怎样把logo转为镂空 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信