// // TerminalVC.m // LNManager // // Created by EchoShacolee on 2017/4/14. // Copyright © 2017年 lee. All rights reserved. // #import "TerminalVC.h" #import #import //添加标注 #import "MyAnimatedAnnotationView.h" #import "MengBanView.h" #import //引入地图功能所有的头文件 #import //引入定位功能所有的头文件 @interface TerminalVC () { BMKMapView * _mapView; NSArray * _pointArr;//点的详情 UISearchBar *_searchBar; MengBanView * _mengBanView; NSString * _status; //地图定位 BMKLocationManager *_locService; } @end @implementation TerminalVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"终端详情"; _pointArr = [NSArray new]; _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, kNavOffSet, kSize.width,kSize.height-64)]; _mapView.mapType = BMKMapTypeStandard; _mapView.zoomLevel = 20; _mapView.showsUserLocation = YES; [self.view addSubview: _mapView]; [self creatSearchBar]; // [self customRightBtn]; _status = @"1"; [self getData]; //定位功能 _locService = [[BMKLocationManager alloc]init]; _locService.distanceFilter = 10;//将被通知任何移动(若=10,表示超出10米才会回调位置信息) _locService.delegate = self; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [_mapView viewWillAppear]; _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放 } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [_mapView viewWillDisappear]; _mapView.delegate = nil; // 不用时,置nil } -(void)creatSearchBar{ _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width, 50)]; _searchBar.delegate = self; _searchBar.tintColor = [UIColor grayColor]; _searchBar.placeholder = @"请输入车牌号查询车辆位置"; [self.view addSubview:_searchBar]; } -(void)customRightBtn{ UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)]; item.tintColor = COLOR_THEME; self.navigationItem.rightBarButtonItem = item; } -(void)setMengbanView{ if (_mengBanView) { [_mengBanView showView]; return; } NSArray * btnarr = @[@"待审核",@"审核通过",@"审核驳回"]; _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:@[btnarr] block:^(NSArray *array) { if ([array[0] isEqualToString:@"待审核"]) { _status = @"0"; }else if ([array[0] isEqualToString:@"审核通过"]){ _status = @"1"; }else if ([array[0] isEqualToString:@"审核驳回"]){ _status = @"2"; } [self getData]; }]; [_mengBanView showView]; } //添加标注 - (void)addPointAnnotationsWithArray:(NSArray *)array{ NSMutableArray *arr = [NSMutableArray new]; for (int i=0; i)annotation { MyAnimatedAnnotationView *annotationView = [MyAnimatedAnnotationView annotationViewWithMapView:mapView Annotation:annotation]; NSInteger i = [annotation.subtitle integerValue]; annotationView.dic = _pointArr[i]; return annotationView; } #pragma mark 百度地图代理相关 - (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status { [_searchBar resignFirstResponder]; } //单击空白处回调处理 - (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate{ [_searchBar resignFirstResponder]; } #pragma mark 定位相关 /**用户拒绝开启定位服务等原因导致的定位失败会调用的方法 */ - (void)didFailToLocateUserWithError:(NSError *)error { //[LoadingView showMsg:@"拒绝将无法自动获取当前位置!"]; UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"未打开位置访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];//@"请在iPhone的“设置”-“隐私”-“定位服务”功能中,找到“极速驾培”打开位置访问权限" [alert show]; [_locService stopUpdatingLocation]; } //处理位置坐标更新 - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation { _mapView.showsUserLocation = YES;//显示定位图层 [_mapView updateLocationData:userLocation]; _mapView.centerCoordinate = userLocation.location.coordinate; } #pragma mark 搜索bar代理 - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{ searchBar.showsCancelButton = YES; UIButton *canceLBtn = [searchBar valueForKey:@"cancelButton"]; [canceLBtn setTitle:@"取消" forState:UIControlStateNormal]; [canceLBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal]; return YES; } - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{ searchBar.showsCancelButton = NO; return YES; } -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ [searchBar resignFirstResponder]; searchBar.text = @""; } //点击键盘上的搜索按钮触发方法 -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ NSMutableArray *mArr = [[NSMutableArray alloc]init]; for (NSDictionary * dic in _pointArr) { if ([dic[@"LICNUM"] containsString:searchBar.text]) { // CLLocationCoordinate2D coor; // coor.latitude = [[NSString stringWithFormat:@"%@",dic[@"LATITUDE"]] floatValue]; // coor.longitude = [[NSString stringWithFormat:@"%@",dic[@"LONGITUDE"]] floatValue]; [mArr addObject:@[dic[@"LATITUDE"],dic[@"LONGITUDE"]]]; } } if (mArr.count == 0) { [self showMsgByMBWithString:@"未找到对应的车辆"]; }else{ CLLocationCoordinate2D coor; coor.latitude = [[NSString stringWithFormat:@"%@",mArr[0][0]] floatValue]; coor.longitude = [[NSString stringWithFormat:@"%@",mArr[0][1]] floatValue]; _mapView.centerCoordinate = coor; for (BMKPointAnnotation *annotation in _mapView.annotations) { if (annotation.coordinate.latitude==coor.latitude && annotation.coordinate.longitude==coor.longitude) { [_mapView selectAnnotation:annotation animated:YES]; } } } } #pragma mark 数据请求 -(void)getData{ NSMutableDictionary * mdic = [NSMutableDictionary new]; [mdic setValue:[NSString stringWithFormat:@"%@",_shcDic?_shcDic[@"TSI_INSCODE"]:@""] forKey:@"inscode"]; [mdic setValue:_status forKey:@"auditStatus"]; [mdic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"]; [mdic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"]; [self getDataWithDic:mdic method:@"devs" block:^(NSDictionary *successdic) { NSMutableArray * mArr = [NSMutableArray arrayWithArray:successdic[@"body"]]; for (NSDictionary * dic in successdic[@"body"]) { if ([dic[@"LATITUDE"] length] == 0) { [mArr removeObject:dic]; } } if (mArr.count == 0) { [_locService startUpdatingLocation]; return; } _pointArr = [NSArray arrayWithArray:mArr]; [self addPointAnnotationsWithArray:_pointArr]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end