123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- //
- // TerminalVC.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/14.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "TerminalVC.h"
- #import <BaiduMapAPI_Map/BMKMapView.h>
- #import <BaiduMapAPI_Map/BMKPointAnnotation.h>//添加标注
- #import <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件
- #import "MyAnimatedAnnotationView.h"
- #import "MengBanView.h"
- @interface TerminalVC ()<BMKMapViewDelegate,UISearchBarDelegate,BMKLocationManagerDelegate>
- {
- BMKMapView * _mapView;
-
- NSArray * _pointArr;//点的详情
-
- UISearchBar *_searchBar;
-
- MengBanView * _mengBanView;
- NSString * _status;
-
- //地图定位
- CLLocationCoordinate2D myLocation;
- }
- @end
- @implementation TerminalVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"终端详情";
-
- _pointArr = [NSArray new];
- _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, kNavOffSet, kSize.width,kSize.height-kNavOffSet)];
- _mapView.mapType = BMKMapTypeStandard;
- _mapView.zoomLevel = 20;
- _mapView.showsUserLocation = YES;
-
- [self.view addSubview: _mapView];
-
- [self creatSearchBar];
-
- // [self customRightBtn];
-
- _status = @"1";
-
- [self getData];
-
- // //定位功能
- // _locService = [[BMKLocationService 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<array.count; i++) {
- BMKPointAnnotation *_pointAnnotation = [[BMKPointAnnotation alloc]init];
- CLLocationCoordinate2D coor;
- coor.latitude = [[NSString stringWithFormat:@"%@",array[i][@"LATITUDE"]] floatValue];
- coor.longitude = [[NSString stringWithFormat:@"%@",array[i][@"LONGITUDE"]] floatValue];
- _pointAnnotation.coordinate = coor;
- _pointAnnotation.title = [NSString stringWithFormat:@"%@and%@",array[i][@"LICNUM"],array[i][@"ISCONNECT"]];
- _pointAnnotation.subtitle = [NSString stringWithFormat:@"%d",i];
-
- [arr addObject:_pointAnnotation];
- // NSLog(@"%f,%f",coor.latitude,coor.longitude);
- //以第一个点为中点
- if (i == 0) {
- _mapView.centerCoordinate = coor;
- }
- }
-
- [_mapView addAnnotations:arr];
- }
- //改变标注图片和自定义气泡
- -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)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)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{
- NSInteger k = 0;
- for (NSDictionary * dic in _pointArr) {
- if ([dic[@"LICNUM"] isEqualToString:searchBar.text]) {
- k++;
- CLLocationCoordinate2D coor;
- coor.latitude = [[NSString stringWithFormat:@"%@",dic[@"LATITUDE"]] floatValue];
- coor.longitude = [[NSString stringWithFormat:@"%@",dic[@"LONGITUDE"]] floatValue];
- _mapView.centerCoordinate = coor;
- }
- }
- if (k == 0) {
- [self showMsgByMBWithString:@"未找到对应的车辆"];
- }
- }
- #pragma mark 数据请求
- -(void)getData{
-
- NSMutableDictionary * mdic = [NSMutableDictionary new];
- [mdic setValue:[NSString stringWithFormat:@"%@",_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 startUserLocationService];
- [self getMyLocation];
- return;
- }
- _pointArr = [NSArray arrayWithArray:mArr];
- [self addPointAnnotationsWithArray:_pointArr];
- }];
- }
- - (void)getMyLocation {
- //定位功能
- [MBProgressHUD showMessage:@"正在获取当前位置..." ToView:self.view];
- [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation *location) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- if (success) {
- self->myLocation = location.coordinate;
- }
- }];
- }
- @end
|