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]}];

  • 相关阅读:
    模板:Prime最小生成树堆优化 + Dijkstra单源最短路堆优化
    线段树
    算法竞赛进阶指南——后缀数组
    浏览器后退刷新页面
    layer.photos()异步修改图片地址后显示异常
    img transform:scale 放大在ios下变模糊
    手机端input[type=date]的placeholder不起作用
    zepto和jQuery on事件委托在苹果手机上的”坑“
    js cookie存取
    js实现消息滚动效果
  • 原文地址:https://www.cnblogs.com/yangqinglong/p/5363408.html
Copyright © 2011-2022 走看看