地图与定位

@import CoreLocation;//经纬度

@import MapKit;//地图库


@interface ViewController ()<CLLocationManagerDelegate,MKMapViewDelegate>

@property(nonatomic,strong) CLLocationManager *locationManage;

@property(nonatomic,strong) MKMapView *mapView;


//加载UI

- (void)setupUI{

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"详情" style:UIBarButtonItemStylePlain target:self action:@selector(details)];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"定位" style:UIBarButtonItemStylePlain target:self action:@selector(positioning)];

    //地图类型切换

    UISegmentedControl *mapTypeSegmentControl = [[UISegmentedControl alloc] initWithItems:@[@"普通", @"卫星", @"混合"]];

    mapTypeSegmentControl.bounds = CGRectMake(0, 0, 200, 25);

    mapTypeSegmentControl.selectedSegmentIndex = 0;

    [mapTypeSegmentControl addTarget:self action:@selector(progressSEgmentControl:) forControlEvents:UIControlEventValueChanged];

    

    UIBarButtonItem *segmentItem = [[UIBarButtonItem alloc] initWithCustomView:mapTypeSegmentControl];

    

    UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];

    self.toolbarItems = @[flexibleItem, segmentItem, flexibleItem];

//实例化地图

    _mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];

//是否显示用户标注

    _mapView.showsUserLocation = YES;

/*

    mapType:设置地图类型

    MKMapTypeStandard:标准地图,一般情况下使用此地图即可满足

    MKMapTypeSatellite:卫星地图

    MKMapTypeHybrid:混合地图,加载最慢比较消耗资源

 */

    _mapView.mapType = MKMapTypeStandard;//标准地图

//设置代理

    _mapView.delegate = self;

    [self.view addSubview: self.mapView];

    

//添加长按手势

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressMapView:)];

    longPress.minimumPressDuration = 1;

    [self.view addGestureRecognizer:longPress];


}

//定位

- (void)positioning{

    [_locationManage startUpdatingLocation];

}

//切换地图

- (void)progressSEgmentControl:(UISegmentedControl *)sender{

    _mapView.mapType = sender.selectedSegmentIndex;

}

//启动定位服务

- (void)loadLocationService{

    //先配置info.plist 关键字 NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription 配置设置选项

    /**

     NSLocationAlwaysUsageDescription 后台一直开启定位服务

     NSLocationWhenInUseUsageDescription 只在程序运行时开启定位服务

     */

    

    //实例化位置管理器

    _locationManage = [[CLLocationManager alloc]init];

    //判断异常情况

    if (![CLLocationManager locationServicesEnabled]) {

        //弹出警告框

        NSLog(@"定位服务不可用");

    }

   

//弹出权限提示框:请求定位授权

    [_locationManage requestWhenInUseAuthorization];

    _locationManage.delegate = self;

    

//定位频率和定位精度并不应当越精确越好,需要视实际情况而定,因为越精确越耗性能,也就越费电。

    //定位精度

    _locationManage.desiredAccuracy = kCLLocationAccuracyBest;//最精确

    //位置更新,最小距离:定位频率

    _locationManage.distanceFilter = kCLDistanceFilterNone;//动一下,更新一下

    //启动定位

    // 注意:开始定位比较耗电,不需要定位的时候最好调用[stopUpdatingLocation]结束定位。

    [_locationManage startUpdatingLocation];

}

//调用位置,查看位置更新是否成功

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

    NSLog(@"位置信息:%@",manager.location);

    //停止定位

    [manager stopUpdatingLocation];

    [self updateMapViewWithLocation:manager.location];

}

//更加新地图

- (void)updateMapViewWithLocation:(CLLocation *)location{

    //跨度

    MKCoordinateSpan span = MKCoordinateSpanMake(0.05, 0.05);

    //范围

    MKCoordinateRegion region = MKCoordinateRegionMake(location.coordinate,  span);

    //配置地图显示区域

    [_mapView setRegion:region animated:YES];

    //配置当前位置的信息

    _mapView.userLocation.title = @"当前位置";

    _mapView.userLocation.subtitle = [NSString stringWithFormat:@"%0.2f,%0.2f",location.coordinate.latitude,location.coordinate.longitude];//调经度和纬度


}

- (void)longPressMapView:(UILongPressGestureRecognizer *)gesture{

    if (gesture.state == UIGestureRecognizerStateBegan) {

        //获取手势坐标

        CGPoint piont = [gesture locationInView:gesture.view];

        //视图坐标转化为经纬度坐标

        CLLocationCoordinate2D coordiante = [_mapView convertPoint:piont toCoordinateFromView:gesture.view ];

        //利用经纬度获取CLLocation

        CLLocation *location = [[CLLocation alloc]initWithLatitude:coordiante.latitude longitude:coordiante.longitude];

        //地理位置逆编码

        [self veverseGeoLocation:location completion:^(BOOL sucess, id content) {

            if (sucess) {

                NSLog(@"%@",content);

                //大头针

                MKPointAnnotation *annotaTion = [[MKPointAnnotation alloc]init];

                annotaTion.coordinate =coordiante;//获得经纬度

                annotaTion.title = content[@"Name"];//标题

                [_mapView addAnnotation:annotaTion];

            }

        }];

        

    }


}

//地理位置逆编码:把经纬度信息编码成格式化的地理位置信息

- (void)veverseGeoLocation:(CLLocation *)location completion:(void(^)(BOOL sucess,id content))completion{

    //逆编码

    CLGeocoder *coder = [[CLGeocoder alloc]init];

    //逆编码方法,后台线程进行

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

        BOOL sucess;

        id content = nil;

        

        if (error) {

            sucess = NO;

            content = error.localizedDescription;

        }else{

            sucess = YES;

            CLPlacemark *placemark = placemarks.firstObject;

            content = placemark.addressDictionary;

        }

        //执行 block

        completion(sucess,content);

    }];


}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{

    if ([annotation isKindOfClass:[MKUserLocation class]]) {

        return  nil;

    }

    //定义标识符

    static NSString *viewIdentifer = @"AnnotationView";

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:viewIdentifer];

    if (!annotationView) {

        annotationView =[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:viewIdentifer];

        //颜色

        annotationView.tintColor = [UIColor redColor];

        //是否动画

        annotationView.animatesDrop = YES;

        //是否需要点击

        annotationView.canShowCallout = YES;

        //配置详细按钮

        UIButton *detaiButton = [UIButton buttonWithType:UIButtonTypeInfoDark];

        annotationView.rightCalloutAccessoryView = detaiButton;

        

    }

    return annotationView;

}

//点击弹出框

- (void)mapVIEW:(MKMapView *)mapView  annotationView:(MKAnnotationView *)view calloutAccessoryContrelTapped:(UIControl *)control{

    NSLog(@"当前位置");

}

主要内容:本文详细介绍了一种QRBiLSTM(分位数回归双向长短期记忆网络)的时间序列区间预测方法。首先介绍了项目背景以及模型的优势,比如能够有效利用双向的信息,并对未来的趋势上限和下限做出估计。接着从数据生成出发讲述了具体的代码操作过程:数据预处理,搭建模型,进行训练,并最终可视化预测结果与计算分位数回归的边界线。提供的示例代码可以完全运行并且包含了数据生成环节,便于新手快速上手,深入学习。此外还指出了模型未来发展的方向,例如加入额外的输入特性和改善超参数配置等途径提高模型的表现。文中强调了时间序列的标准化和平稳检验,在样本划分阶段需要按时间序列顺序进行划分,并在训练阶段采取合适的手段预防过度拟合发生。 适合人群:对于希望学习和应用双向长短时记忆网络解决时序数据预测的初学者和具有一定基础的研究人员。尤其适用于有金融数据分析需求、需要做多一步或多步预测任务的从业者。 使用场景及目标:应用于金融市场波动预报、天气状况变化预测或是物流管理等多个领域内的决策支持。主要目的在于不仅能够提供精确的数值预计还能描绘出相应的区间概率图以增强结论置信程度。 补充说明:本教程通过一个由正弦信号加白噪构造而成的简单实例来指导大家理解和执行QRBiLSTM流程的所有关键步骤,这既方便于初学者跟踪学习,又有利于专业人士作为现有系统的补充参考工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值