TerminalVC.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // TerminalVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/14.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "TerminalVC.h"
  9. #import <BaiduMapAPI_Map/BMKMapView.h>
  10. #import <BaiduMapAPI_Map/BMKPointAnnotation.h>//添加标注
  11. #import "MyAnimatedAnnotationView.h"
  12. #import "MengBanView.h"
  13. #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
  14. #import <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件
  15. @interface TerminalVC ()<BMKMapViewDelegate,UISearchBarDelegate,BMKLocationManagerDelegate>
  16. {
  17. BMKMapView * _mapView;
  18. NSArray * _pointArr;//点的详情
  19. UISearchBar *_searchBar;
  20. MengBanView * _mengBanView;
  21. NSString * _status;
  22. //地图定位
  23. BMKLocationManager *_locService;
  24. }
  25. @end
  26. @implementation TerminalVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.navigationItem.title = @"终端详情";
  30. _pointArr = [NSArray new];
  31. _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, kNavOffSet, kSize.width,kSize.height-64)];
  32. _mapView.mapType = BMKMapTypeStandard;
  33. _mapView.zoomLevel = 20;
  34. _mapView.showsUserLocation = YES;
  35. [self.view addSubview: _mapView];
  36. [self creatSearchBar];
  37. // [self customRightBtn];
  38. _status = @"1";
  39. [self getData];
  40. //定位功能
  41. _locService = [[BMKLocationManager alloc]init];
  42. _locService.distanceFilter = 10;//将被通知任何移动(若=10,表示超出10米才会回调位置信息)
  43. _locService.delegate = self;
  44. }
  45. -(void)viewWillAppear:(BOOL)animated
  46. {
  47. [super viewWillAppear:animated];
  48. [_mapView viewWillAppear];
  49. _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
  50. }
  51. -(void)viewWillDisappear:(BOOL)animated
  52. {
  53. [super viewWillDisappear:animated];
  54. [_mapView viewWillDisappear];
  55. _mapView.delegate = nil; // 不用时,置nil
  56. }
  57. -(void)creatSearchBar{
  58. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width, 50)];
  59. _searchBar.delegate = self;
  60. _searchBar.tintColor = [UIColor grayColor];
  61. _searchBar.placeholder = @"请输入车牌号查询车辆位置";
  62. [self.view addSubview:_searchBar];
  63. }
  64. -(void)customRightBtn{
  65. UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)];
  66. item.tintColor = COLOR_THEME;
  67. self.navigationItem.rightBarButtonItem = item;
  68. }
  69. -(void)setMengbanView{
  70. if (_mengBanView) {
  71. [_mengBanView showView];
  72. return;
  73. }
  74. NSArray * btnarr = @[@"待审核",@"审核通过",@"审核驳回"];
  75. _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:@[btnarr] block:^(NSArray *array) {
  76. if ([array[0] isEqualToString:@"待审核"]) {
  77. _status = @"0";
  78. }else if ([array[0] isEqualToString:@"审核通过"]){
  79. _status = @"1";
  80. }else if ([array[0] isEqualToString:@"审核驳回"]){
  81. _status = @"2";
  82. }
  83. [self getData];
  84. }];
  85. [_mengBanView showView];
  86. }
  87. //添加标注
  88. - (void)addPointAnnotationsWithArray:(NSArray *)array{
  89. NSMutableArray *arr = [NSMutableArray new];
  90. for (int i=0; i<array.count; i++) {
  91. BMKPointAnnotation *_pointAnnotation = [[BMKPointAnnotation alloc]init];
  92. CLLocationCoordinate2D coor;
  93. coor.latitude = [[NSString stringWithFormat:@"%@",array[i][@"LATITUDE"]] floatValue];
  94. coor.longitude = [[NSString stringWithFormat:@"%@",array[i][@"LONGITUDE"]] floatValue];
  95. _pointAnnotation.coordinate = coor;
  96. _pointAnnotation.title = [NSString stringWithFormat:@"%@and%@",array[i][@"LICNUM"],array[i][@"ISCONNECT"]];
  97. _pointAnnotation.subtitle = [NSString stringWithFormat:@"%d",i];
  98. [arr addObject:_pointAnnotation];
  99. // NSLog(@"%f,%f",coor.latitude,coor.longitude);
  100. //以第一个点为中点
  101. if (i == 0) {
  102. _mapView.centerCoordinate = coor;
  103. }
  104. }
  105. [_mapView addAnnotations:arr];
  106. }
  107. //改变标注图片和自定义气泡
  108. -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
  109. {
  110. MyAnimatedAnnotationView *annotationView = [MyAnimatedAnnotationView annotationViewWithMapView:mapView Annotation:annotation];
  111. NSInteger i = [annotation.subtitle integerValue];
  112. annotationView.dic = _pointArr[i];
  113. return annotationView;
  114. }
  115. #pragma mark 百度地图代理相关
  116. - (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status {
  117. [_searchBar resignFirstResponder];
  118. }
  119. //单击空白处回调处理
  120. - (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate{
  121. [_searchBar resignFirstResponder];
  122. }
  123. #pragma mark 定位相关
  124. /**用户拒绝开启定位服务等原因导致的定位失败会调用的方法
  125. */
  126. - (void)didFailToLocateUserWithError:(NSError *)error
  127. {
  128. //[LoadingView showMsg:@"拒绝将无法自动获取当前位置!"];
  129. UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"未打开位置访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];//@"请在iPhone的“设置”-“隐私”-“定位服务”功能中,找到“极速驾培”打开位置访问权限"
  130. [alert show];
  131. [_locService stopUpdatingLocation];
  132. }
  133. //处理位置坐标更新
  134. - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
  135. {
  136. _mapView.showsUserLocation = YES;//显示定位图层
  137. [_mapView updateLocationData:userLocation];
  138. _mapView.centerCoordinate = userLocation.location.coordinate;
  139. }
  140. #pragma mark 搜索bar代理
  141. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
  142. searchBar.showsCancelButton = YES;
  143. UIButton *canceLBtn = [searchBar valueForKey:@"cancelButton"];
  144. [canceLBtn setTitle:@"取消" forState:UIControlStateNormal];
  145. [canceLBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  146. return YES;
  147. }
  148. - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
  149. searchBar.showsCancelButton = NO;
  150. return YES;
  151. }
  152. -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
  153. [searchBar resignFirstResponder];
  154. searchBar.text = @"";
  155. }
  156. //点击键盘上的搜索按钮触发方法
  157. -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  158. NSMutableArray *mArr = [[NSMutableArray alloc]init];
  159. for (NSDictionary * dic in _pointArr) {
  160. if ([dic[@"LICNUM"] containsString:searchBar.text]) {
  161. // CLLocationCoordinate2D coor;
  162. // coor.latitude = [[NSString stringWithFormat:@"%@",dic[@"LATITUDE"]] floatValue];
  163. // coor.longitude = [[NSString stringWithFormat:@"%@",dic[@"LONGITUDE"]] floatValue];
  164. [mArr addObject:@[dic[@"LATITUDE"],dic[@"LONGITUDE"]]];
  165. }
  166. }
  167. if (mArr.count == 0) {
  168. [self showMsgByMBWithString:@"未找到对应的车辆"];
  169. }else{
  170. CLLocationCoordinate2D coor;
  171. coor.latitude = [[NSString stringWithFormat:@"%@",mArr[0][0]] floatValue];
  172. coor.longitude = [[NSString stringWithFormat:@"%@",mArr[0][1]] floatValue];
  173. _mapView.centerCoordinate = coor;
  174. for (BMKPointAnnotation *annotation in _mapView.annotations) {
  175. if (annotation.coordinate.latitude==coor.latitude && annotation.coordinate.longitude==coor.longitude) {
  176. [_mapView selectAnnotation:annotation animated:YES];
  177. }
  178. }
  179. }
  180. }
  181. #pragma mark 数据请求
  182. -(void)getData{
  183. NSMutableDictionary * mdic = [NSMutableDictionary new];
  184. [mdic setValue:[NSString stringWithFormat:@"%@",_shcDic?_shcDic[@"TSI_INSCODE"]:@""] forKey:@"inscode"];
  185. [mdic setValue:_status forKey:@"auditStatus"];
  186. [mdic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  187. [mdic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  188. [self getDataWithDic:mdic method:@"devs" block:^(NSDictionary *successdic) {
  189. NSMutableArray * mArr = [NSMutableArray arrayWithArray:successdic[@"body"]];
  190. for (NSDictionary * dic in successdic[@"body"]) {
  191. if ([dic[@"LATITUDE"] length] == 0) {
  192. [mArr removeObject:dic];
  193. }
  194. }
  195. if (mArr.count == 0) {
  196. [_locService startUpdatingLocation];
  197. return;
  198. }
  199. _pointArr = [NSArray arrayWithArray:mArr];
  200. [self addPointAnnotationsWithArray:_pointArr];
  201. }];
  202. }
  203. - (void)didReceiveMemoryWarning {
  204. [super didReceiveMemoryWarning];
  205. // Dispose of any resources that can be recreated.
  206. }
  207. /*
  208. #pragma mark - Navigation
  209. // In a storyboard-based application, you will often want to do a little preparation before navigation
  210. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  211. // Get the new view controller using [segue destinationViewController].
  212. // Pass the selected object to the new view controller.
  213. }
  214. */
  215. @end