//
// ViewController.m
// map
//
// Created by mac on 15/7/23.
// Copyright (c) 2015年 xin. All rights reserved.
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate>
@property (nonatomic, strong)CLLocationManager *locMar;
@end
@implementation ViewController
- (CLLocationManager *)locMar{
if (_locMar == nil) {
self.locMar = [[CLLocationManager alloc] init];
self.locMar.delegate = self;
}
return _locMar;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if ([CLLocationManager locationServicesEnabled]) {
[self.locMar startUpdatingLocation];
self.locMar.distanceFilter = kCLDistanceFilterNone;
self.locMar.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[_locMar startUpdatingLocation];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
[_locMar requestWhenInUseAuthorization]; //调用了这句,就会弹出允许框了.
}
}else{
NSLog(@"打开权限");
}
[self countDistance];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *loc = [locations firstObject];
NSLog(@"纬度=%f,经度=%f",loc.coordinate.latitude,loc.coordinate.longitude);
}
//计算两个位置之间的距离
-(void)countDistance
{
//根据经纬度创建两个位置对象
CLLocation *loc1=[[CLLocation alloc]initWithLatitude:40 longitude:116];
CLLocation *loc2=[[CLLocation alloc]initWithLatitude:41 longitude:116];
//计算两个位置之间的距离
CLLocationDistance distance=[loc1 distanceFromLocation:loc2];
NSLog(@"(%@)和(%@)的距离=%fM",loc1,loc2,distance);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
在plist里面包含这两个属性