zoukankan      html  css  js  c++  java
  • IOS简单的定位

    @property (nonatomic,strong) CLLocationManager *locationManager;

    @property (nonatomic,strong) CLGeocoder *geoCoder;

    if([CLLocationManager locationServicesEnabled]){

            self.locationManager = [[CLLocationManager alloc]init];

            _locationManager.desiredAccuracy = kCLLocationAccuracyBest;

            _locationManager.delegate =self;

            //ios8.0以上

            if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0) {

                [_locationManager requestAlwaysAuthorization];

            }

            //开始获取位置

            [_locationManager startUpdatingLocation];

            //获取当前的时间

            NSDate *nowDate = [NSDate date];

            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

            formatter.dateFormat = @"yy/MMM/dd EE aa H:mm;ss";

            NSString *formatDateString = [formatter stringFromDate:nowDate];

            NSLog(@"%@",formatDateString);

        }

    }

    //定位失败

    -(void)locationManager:(CLLocationManager *)manager didFailWithError:(nonnull NSError *)error{

        

    }

    //定位在一直更新

    -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{

        //暂停位置更新

        [_locationManager stopUpdatingLocation];

        NSLog(@"%@",locations);

        //获取最新的location

        CLLocation *newLocation = [locations lastObject];

        

        //将location 反编码

        self.geoCoder = [[CLGeocoder alloc]init];

        [_geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

            //获取placeMark

            CLPlacemark *placeMark = [placemarks lastObject];

            NSLog(@"%@",placeMark.name);

        }];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    地图导航“         

            CLLocationCoordinate2D endCoor = CLLocationCoordinate2DMake(self.latitude, self.longitude);//目的地经纬度        

            MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];//用户当前位置

            MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:endCooraddressDictionary:nil]];

            toLocation.name = self.titleOnMark;//目的地名称

            [MKMapItem openMapsWithItems:@[currentLocation, toLocation];

                           launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];

  • 相关阅读:
    20151124 Jquery UI form 表单变成dialog
    如何创建windows xp 虚拟机
    mySQL 从删库到跑路
    CF962D Merge Equals
    hihocoder1718 最长一次上升子序列
    2018微软实习笔试一道dp题目总结
    poj3783 Balls
    CF961E Tufurama
    蓝桥杯 高僧斗法
    蓝桥杯 国王的烦恼
  • 原文地址:https://www.cnblogs.com/yangqinglong/p/5363408.html
Copyright © 2011-2022 走看看