iOS中定位当前位置坐标及转换为火星坐标的方法

2020-01-14 20:05:30丽君
易采站长站为您分析iOS中获取当前位置坐标及转换为火星坐标的方法,这里的火星坐标指的是我国专门研制的一种加密的坐标系统...需要的朋友可以参考下  

定位和位置信息获取
定位和反查位置信息要加载两个动态库 CoreLocation.framework 和 MapKit.framework 一个获取坐标一个提供反查

复制代码
// appDelgate.h 
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
 
@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate,MKReverseGeocoderDelegate>
 
@property (strong, nonatomic) UIWindow *window;
 
@end
  复制代码
#import "AppDelegate.h"
 
 
@implementation AppDelegate
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    button.frame = CGRectMake(0, 100, 100, 30);
    [button setTitle:@"定位" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
     
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, 320, 30)];
    label.tag = 101;
    label.text = @"等待定位中....";
    [self.window addSubview:label];
    [label release];
    [self.window addSubview:button];
    return YES;
 
}
 
-(void) test {
     
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    // 设置定位精度,十米,百米,最好
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    locationManager.delegate = self;
     
    // 开始时时定位
    [locationManager startUpdatingLocation];
}
 
// 错误信息
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {