| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- //
- // JOGetLocationViewController.m
- // shiku_im
- //
- // Created by 周兵 on 16/7/19.
- // Copyright © 2016年 Reese. All rights reserved.
- //
- #import "JOGetLocationViewController.h"
- #import "JOPOIAnnotation.h"
- #import "JZLocationConverter.h"
- #import "Reachability.h"
- #import "UASLocaManager.h"
- @interface JOGetLocationViewController ()<MAMapViewDelegate,AMapSearchDelegate,AMapNearbySearchManagerDelegate,MKMapViewDelegate,UITableViewDataSource,UITableViewDelegate>
- {
-
- MAMapView *_mapView;
- AMapSearchAPI *_search;
- UITableView * _tableView;
- UILabel * _tixing;
-
- //两个数组
- NSMutableArray * _addressArr;
- NSMutableArray * _subAddressArr;
- NSMutableArray * _jinweiduArrTwo;
- NSMutableArray * _juliduoshaomiyuan;
-
- CGFloat lat;
- CGFloat loo;
-
- }
- @property (nonatomic, strong) Reachability *conn;//网络监控
- @property(strong,nonatomic)UASLocaManager *locaManager;
- @end
- @implementation JOGetLocationViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initMapView];
-
- _addressArr=[[NSMutableArray alloc]init];
- _subAddressArr=[[NSMutableArray alloc]init];
- _jinweiduArrTwo=[[NSMutableArray alloc]init];
- _juliduoshaomiyuan=[[NSMutableArray alloc]init];
-
- [self initTableView];
-
- [self setNavi];
-
- _tixing=[[UILabel alloc]init];
- _tixing.frame=CGRectMake(self_width/2-200/2,40,200,80);
- _tixing.numberOfLines = 0;
- _tixing.text=Localized(@"UU_work_OA_punchClock_title8");
- _tixing.textColor=self.naviColor;
- _tixing.hidden=YES;
- [_tableView addSubview:_tixing];
-
-
-
- //监听
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kReachabilityChangedNotification object:nil];
-
- self.conn = [Reachability reachabilityForInternetConnection];
-
- [self.conn startNotifier];
-
-
- NSString * str=[self getNetWorkStates];
- if ([str isEqualToString:@"2G"]||[str isEqualToString:@"3G"])
- {
- [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境不佳,建议切换到4G网络" ToNavi:self.navigationController withColor:nil];
- }
-
-
-
- }
- - (void)setNavi
- {
-
- CGFloat height = 0;
-
- if (statusX) {
-
- height = 0;
- }
- UIImageView * view =[[UIImageView alloc]init];
- view.frame=CGRectMake(0,0,self_width,64+height);
- view.image = [UIImage imageNamed:@"UU_newbg2"];
- view.userInteractionEnabled = YES;
-
- [self.view addSubview:view];
-
-
- UIImageView * images=[[UIImageView alloc]initWithFrame:CGRectMake(15, 30+height, 22, 22)];
- images.image=[UIImage imageNamed:@"icon_back_nor3"];
- [view addSubview:images];
- UIButton * quxiao=[UIButton buttonWithType:UIButtonTypeCustom];
- quxiao.frame=CGRectMake(0,0+height,64,64);
- //[quxiao setImage:[UIImage imageNamed:@"nav_btn_back"] forState:UIControlStateNormal];
- [quxiao setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [quxiao addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
- [view addSubview:quxiao];
-
- UILabel * titleLabel=[[UILabel alloc]init];
- titleLabel.frame=CGRectMake((self_width-200)/2,30+height, 200,24);
- titleLabel.text=Localized(@"UU_work_OA_punchClock_addressLittechange");
- titleLabel.textAlignment=1;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- titleLabel.font=YBLBFont(16);
- titleLabel.textColor=[UIColor whiteColor];
- [view addSubview:titleLabel];
-
- }
- - (void)fanhui
- {
- [self dismissViewControllerAnimated:YES completion:^{
-
- }];
-
- }
- - (void)initTableView
- {
- _tableView=[[UITableView alloc]init];
- _tableView.frame=CGRectMake(0,(self_height-64)/2+64,self_width,(self_height-64)/2);
- _tableView.dataSource=self;
- _tableView.delegate=self;
- [self setExtraCellLineHidden:_tableView];
- [self.view addSubview:_tableView];
- }
- - (void)initMapView
- {
- CGFloat height = 0;
-
- if (statusX) {
-
- height = 0;
- }
- __weak typeof(JOGetLocationViewController) *weakSelf = self;
- self.locaManager = [[UASLocaManager alloc]initWithMapviewLocationUpdate:^(UASUserLocation *location, NSError *error) {
-
-
- __strong typeof(JOGetLocationViewController) *strongSelf = weakSelf;
-
- if (!strongSelf) {
-
- return;
-
- }
- strongSelf->lat=location.location.coordinate.latitude;
- strongSelf->loo=location.location.coordinate.longitude;
-
- [strongSelf initSearch];
-
- }];
-
- self.locaManager.mapView.frame = CGRectMake(0,64+height,self_width,(self_height-64)/2);
-
- self.locaManager.updateDistance = 10;
-
- [self.view addSubview:self.locaManager.mapView];
-
- //
- // if ([UASUserInfo shareManager].inRegion) {//区域内地图
- //
- // _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0,64+height,self_width,(self_height-64)/2)];
- //
- // _mapView.delegate = self;
- // // 不显示罗盘
- // _mapView.showsCompass = NO;
- // // 不显示比例尺
- // _mapView.showsScale = NO;
- // // 地图缩放等级
- // [_mapView setZoomLevel:16.1 animated:YES];
- // [_mapView setZoomEnabled:YES];
- // // 开启定位
- // _mapView.showsUserLocation = YES;
- //
- //
- // [self.view addSubview:_mapView];
- //
- // }else{//区域外地图
- //
- // self.mkMapView = [[MKMapView alloc]initWithFrame:CGRectMake(0,64+height,self_width,(self_height-64)/2)];
- //
- // self.mkMapView.delegate = self;
- //
- // self.mkMapView.showsCompass = NO;
- //
- // self.mkMapView.showsScale = NO;
- //
- // [self.mkMapView setZoomEnabled:YES];
- //
- // self.mkMapView.showsUserLocation = YES;
- //
- // [self.view addSubview:self.mkMapView];
- //
- //
- // }
- }
- //- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
- //
- //
- // [self.mkMapView setCenterCoordinate:userLocation.coordinate zoomLevel:16 animated:0];
- //
- // lat=userLocation.coordinate.latitude;
- // loo=userLocation.coordinate.longitude;
- //
- // [self initSearch];
- //
- //}
- /**
- 当位置更新时,会进定位回调,通过回调函数,能获取到定位点的经纬度坐标
- */
- - (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
- updatingLocation:(BOOL)updatingLocation
- {
- if(updatingLocation)
- {
- [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude) animated:YES];
- lat=userLocation.coordinate.latitude;
- loo=userLocation.coordinate.longitude;
-
- [self initSearch];
-
-
- }
- }
- - (void)initSearch
- {
-
- CLLocation *location = [[CLLocation alloc]initWithLatitude:lat longitude:loo];
-
- __weak typeof(JOGetLocationViewController) *weakSelf = self;
- [self.locaManager searchNearbyPlace:location distance:500 completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
-
-
- __strong typeof(JOGetLocationViewController) *strongSelf = weakSelf;
-
- if (!strongSelf) {
-
- return;
-
- }
-
- if(result.count == 0)
- {
- return;
- }
-
- if (strongSelf->_jinweiduArrTwo.count>0)
- {
- return;
- }
-
- [strongSelf->_juliduoshaomiyuan removeAllObjects];
- [strongSelf->_addressArr removeAllObjects];
- [strongSelf->_subAddressArr removeAllObjects];
- [strongSelf->_jinweiduArrTwo removeAllObjects];
-
-
- NSMutableArray * empArray=[[NSMutableArray alloc]init];
- for (int i=1; i<result.count; i++)
- {
- AMapPOI * m = result[i];
-
- if (strongSelf.jingweiduArray.count==3)
- {
-
- int juli=[strongSelf calculateDistence:[[CLLocation alloc]initWithLatitude:m.location.latitude longitude:m.location.longitude]];
-
- if (juli<[strongSelf.jingweiduArray[0] integerValue])
- {
-
- [empArray addObject:[NSString stringWithFormat:@"%d",juli]];
- [strongSelf->_juliduoshaomiyuan addObject:[NSString stringWithFormat:@"%d",juli]];
- [strongSelf->_addressArr addObject:m.name];
- [strongSelf->_subAddressArr addObject:[NSString stringWithFormat:@"%@%@%@%@",m.province,m.city,m.district,m.address]];
- [strongSelf->_jinweiduArrTwo addObject:m.location];
- }
-
-
-
-
- //剔除超出范围地点
-
- }
- else
- {
-
- [strongSelf->_addressArr addObject:m.name];
- [strongSelf->_subAddressArr addObject:[[[m.province stringByAppendingString:m.city] stringByAppendingString:m.district] stringByAppendingString:m.address]];
- [strongSelf->_jinweiduArrTwo addObject:m.location];
-
- }
-
-
-
- }
-
-
-
- //刷新之前进行排序
-
- if (strongSelf.jingweiduArray.count==3)
- {
-
- [strongSelf buddleSort:empArray];
-
- }
-
-
- [strongSelf->_tableView reloadData];
-
- if (strongSelf->_addressArr.count==0)
- {
- strongSelf->_tixing.hidden=NO;
- }
-
-
-
-
- }];
-
- // if ([UASUserInfo shareManager].inRegion) {
- //
- // _search = [[AMapSearchAPI alloc] init];
- // _search.delegate = self;
- //
- // //构造AMapPOIAroundSearchRequest对象,设置周边请求参数
- // AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
- // request.location = [AMapGeoPoint locationWithLatitude:lat longitude:loo];
- // request.keywords = @"";
- //
- // request.types = @"汽车服务|汽车销售|汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|医疗保健服务|住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施";
- // //设置微调距离
- // request.radius=500;
- // if ([self.type isEqualToString:@"waiqingqiandao"])
- // {
- // NSUserDefaults * user=[NSUserDefaults standardUserDefaults];
- // NSString * duoshaomiya=[NSString stringWithFormat:@"%@",[user objectForKey:@"woyaocunduoshaomi"]];
- // DLog(@"%@",duoshaomiya);
- //// if ([duoshaomiya isEqualToString:@"500"])
- //// {
- //// request.radius=500;
- //// }else if ([duoshaomiya isEqualToString:@"200"])
- //// {
- //// request.radius=200;
- ////
- //// }else if ([duoshaomiya isEqualToString:@"50"])
- //// {
- //// request.radius=50;
- //// }
- // request.radius = [duoshaomiya integerValue];
- // }
- // // DLog(@"设置外勤范围:%ld",(long)request.radius);
- //
- // request.sortrule = 0;
- // request.requireExtension = YES;
- // request.requireSubPOIs=YES;
- // //发起周边搜索
- // [_search AMapPOIAroundSearch: request];
- //
- // }else{
- //
- // [_juliduoshaomiyuan removeAllObjects];
- // [_addressArr removeAllObjects];
- // [_subAddressArr removeAllObjects];
- // [_jinweiduArrTwo removeAllObjects];
- //
- // MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
- // request.naturalLanguageQuery = @"地名|餐饮|银行";
- // request.region = self.mkMapView.region;
- // MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
- // [search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
- //
- //
- // NSMutableArray * empArray=[[NSMutableArray alloc]init];
- // for (MKMapItem *item in response.mapItems)
- // {
- //
- // NSString *location = [NSString stringWithFormat:@"%@%@%@%@%@%@",item.placemark.country,item.placemark.subLocality,item.placemark.locality,item.placemark.thoroughfare,item.placemark.thoroughfare,item.placemark.name];
- //
- // if (self.jingweiduArray.count==3)
- // {
- //
- // int juli=[self calculateDistence:item.placemark.location];
- //
- // if (juli<[self.jingweiduArray[0] integerValue])
- // {
- //
- // [empArray addObject:[NSString stringWithFormat:@"%d",juli]];
- // [_juliduoshaomiyuan addObject:[NSString stringWithFormat:@"%d",juli]];
- // [_addressArr addObject:item.name];
- // AMapGeoPoint *point = [AMapGeoPoint locationWithLatitude:item.placemark.location.coordinate.latitude longitude:item.placemark.location.coordinate.longitude];
- // [_subAddressArr addObject:location];
- // [_jinweiduArrTwo addObject:point];
- //
- // }
- // //剔除超出范围地点
- //
- // }
- // else
- // {
- //
- // [_addressArr addObject:item.name];
- // [_subAddressArr addObject:location];
- // AMapGeoPoint *point = [AMapGeoPoint locationWithLatitude:item.placemark.location.coordinate.latitude longitude:item.placemark.location.coordinate.longitude];
- // [_jinweiduArrTwo addObject:point];
- //
- // }
- //
- //
- //
- // }
- //
- // //刷新之前进行排序
- // if (self.jingweiduArray.count==3)
- // {
- //
- // [self buddleSort:empArray];
- //
- // }
- //
- //
- // [_tableView reloadData];
- //
- // if (_addressArr.count==0)
- // {
- // _tixing.hidden=NO;
- // }
- //
- //
- // }];
- //
- // }
-
- }
- - (void)setSelectedLocationWithLocation:(AMapPOI *)poi
- {
- [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(poi.location.latitude,poi.location.longitude) animated:NO];
-
- }
- //实现POI搜索对应的回调函数
- - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
- {
- if(response.pois.count == 0)
- {
- return;
- }
-
- if (_jinweiduArrTwo.count>0)
- {
- return;
- }
-
- [_juliduoshaomiyuan removeAllObjects];
- [_addressArr removeAllObjects];
- [_subAddressArr removeAllObjects];
- [_jinweiduArrTwo removeAllObjects];
-
-
- NSMutableArray * empArray=[[NSMutableArray alloc]init];
- for (int i=1; i<response.pois.count; i++)
- {
- AMapPOI * m=response.pois[i];
-
- if (self.jingweiduArray.count==3)
- {
-
- int juli=[self calculateDistence:[[CLLocation alloc]initWithLatitude:m.location.latitude longitude:m.location.longitude]];
-
- if (juli<[self.jingweiduArray[0] integerValue])
- {
-
- [empArray addObject:[NSString stringWithFormat:@"%d",juli]];
- [_juliduoshaomiyuan addObject:[NSString stringWithFormat:@"%d",juli]];
- [_addressArr addObject:m.name];
- [_subAddressArr addObject:[NSString stringWithFormat:@"%@%@%@%@",m.province,m.city,m.district,m.address]];
- [_jinweiduArrTwo addObject:m.location];
- }
-
-
-
-
- //剔除超出范围地点
-
- }
- else
- {
-
- [_addressArr addObject:m.name];
- [_subAddressArr addObject:[[[m.province stringByAppendingString:m.city] stringByAppendingString:m.district] stringByAppendingString:m.address]];
- [_jinweiduArrTwo addObject:m.location];
-
- }
-
-
-
- }
-
-
-
- //刷新之前进行排序
-
- if (self.jingweiduArray.count==3)
- {
-
- [self buddleSort:empArray];
-
- }
-
-
- [_tableView reloadData];
-
- if (_addressArr.count==0)
- {
- _tixing.hidden=NO;
- }
-
- }
- #pragma - mark 冒泡排序
- - (void)buddleSort:(NSMutableArray *)array
- {
-
- //DLog(@"里面时多少%@",array);
-
-
-
- for (int i = 1; i < array.count; i++)
- {
- for (int j = 0; j < array.count - i; j++)
- {
-
- if ([array[j] intValue] > [array[j+1] intValue])
- {
- [array exchangeObjectAtIndex:j withObjectAtIndex:j+1];
-
- [_juliduoshaomiyuan exchangeObjectAtIndex:j withObjectAtIndex:j+1];
- [_addressArr exchangeObjectAtIndex:j withObjectAtIndex:j+1];
- [_subAddressArr exchangeObjectAtIndex:j withObjectAtIndex:j+1];
- [_jinweiduArrTwo exchangeObjectAtIndex:j withObjectAtIndex:j+1];
- }
-
- }
- }
- DLog(@"排序%@",array);
- // for (int i=0; i<_juliduoshaomiyuan.count; i++)
- // {
- // if ([_juliduoshaomiyuan[i] integerValue]<10)
- // {
- // [_juliduoshaomiyuan exchangeObjectAtIndex:0 withObjectAtIndex:i];
- // [_addressArr exchangeObjectAtIndex:0 withObjectAtIndex:i];
- // [_subAddressArr exchangeObjectAtIndex:0 withObjectAtIndex:i];
- // [_jinweiduArr exchangeObjectAtIndex:0 withObjectAtIndex:i];
- // }
- // }
-
-
- }
- - (CGFloat)calculateDistence:(CLLocation *)point
- {
-
- CLLocationDistance distance = 0;
- CGFloat jingwdu=[self.jingweiduArray[1] doubleValue];
- CGFloat weidu=[self.jingweiduArray[2] doubleValue];
-
- if ([UASUserInfo shareManager].inRegion) {
-
- MAMapPoint point1 = MAMapPointForCoordinate(CLLocationCoordinate2DMake(point.coordinate.latitude,point.coordinate.longitude));
-
- MAMapPoint point2 = MAMapPointForCoordinate([JZLocationConverter changeBaiduCoordinateToCOMMON:CLLocationCoordinate2DMake(weidu,jingwdu)]);
-
-
- distance = MAMetersBetweenMapPoints(point1,point2);
-
- }else{
-
- CLLocation *loca1 = [[CLLocation alloc]initWithLatitude:point.coordinate.latitude longitude:point.coordinate.longitude];
-
- CLLocation *loca2 = [[CLLocation alloc]initWithLatitude:weidu longitude:jingwdu];;
-
- distance = [loca1 distanceFromLocation:loca2];
-
- // MKMapPoint point1 = MKMapPointMake(point.coordinate.latitude, point.coordinate.longitude);
- //
- // MKMapPoint point2 = MKMapPointMake(weidu, jingwdu);
- //
- // distance = MKMetersBetweenMapPoints(point1, point2);
-
- }
-
- return distance;
-
- }
- #pragma mark - tableView展示区域
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- return _addressArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 50;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- //1.cell初始化
- static NSString *identifier = @"cell";
- UITableViewCell * cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
-
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
-
- UILabel * bigLabel=[[UILabel alloc]init];
- bigLabel.frame=CGRectMake(10,3,self_width-40,20);
- bigLabel.font=FONT_SIZE(13);
- bigLabel.textColor=[UIColor blackColor];
- if (_addressArr.count>indexPath.row) {
-
- bigLabel.text=_addressArr[indexPath.row];
-
-
- }
- [cell.contentView addSubview:bigLabel];
-
-
- UILabel * subLabel=[[UILabel alloc]init];
- subLabel.frame=CGRectMake(10,20,self_width-40,30);
- subLabel.font=FONT_SIZE(11);
- subLabel.numberOfLines = 0;
- subLabel.textColor=Color(160,160,160,1.0);
-
- if (_subAddressArr.count > indexPath.row) {
-
- subLabel.text=[NSString stringWithFormat:@"%@",_subAddressArr[indexPath.row]];
-
- }
-
- [cell.contentView addSubview:subLabel];
-
- if (self.jingweiduArray.count==3)
- {
- UILabel * juliLabel=[[UILabel alloc]init];
- juliLabel.frame=CGRectMake(self_width-60,5,50,20);
- juliLabel.font=FONT_SIZE(12);
- juliLabel.textColor=Color(160,160,160,1.0);
- juliLabel.textAlignment=1;
- if (_juliduoshaomiyuan.count > indexPath.row) {
-
- juliLabel.text=[NSString stringWithFormat:@"%@%@",_juliduoshaomiyuan[indexPath.row],Localized(@"UU_work_OA_punchClock_rice")];
-
- }
- [cell.contentView addSubview:juliLabel];
-
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if (self.jingweiduArray.count==3)
- {
- [self dismissViewControllerAnimated:YES completion:^{
-
-
- if ([UASUserInfo shareManager].inRegion) {
-
- AMapGeoPoint * p=_jinweiduArrTwo[indexPath.row];
- NSString * str1=[NSString stringWithFormat:@"%f",p.latitude];
- NSString * str2=[NSString stringWithFormat:@"%f",p.longitude];
- NSString * str3=[NSString stringWithFormat:@"%@",_juliduoshaomiyuan[indexPath.row]];
-
- NSArray * arr=[NSArray arrayWithObjects:str1,str2,str3,nil];
- self.selectName(_addressArr[indexPath.row],_subAddressArr[indexPath.row],arr);
-
- }else{
-
- CLLocation * p=_jinweiduArrTwo[indexPath.row];
- NSString * str1=[NSString stringWithFormat:@"%f",p.coordinate.latitude];
- NSString * str2=[NSString stringWithFormat:@"%f",p.coordinate.longitude];
- NSString * str3=[NSString stringWithFormat:@"%@",_juliduoshaomiyuan[indexPath.row]];
-
- NSArray * arr=[NSArray arrayWithObjects:str1,str2,str3,nil];
- self.selectName(_addressArr[indexPath.row],_subAddressArr[indexPath.row],arr);
-
- }
-
- }];
-
- }
- else
- {
-
- [self dismissViewControllerAnimated:YES completion:^{
-
- AMapGeoPoint * p=_jinweiduArrTwo[indexPath.row];
- NSString * str1=[NSString stringWithFormat:@"%f",p.latitude];
- NSString * str2=[NSString stringWithFormat:@"%f",p.longitude];
- NSArray * arr=[NSArray arrayWithObjects:str1,str2,nil];
- self.selectName(_addressArr[indexPath.row],_subAddressArr[indexPath.row],arr);
-
- }];
- }
-
- }
- - (void)backname:(backAddress)name
- {
- self.selectName=name;
- }
- /**
- 去掉分割线
- */
- - (void)setExtraCellLineHidden: (UITableView *)tableView
- {
-
- UIView *view = [UIView new];
-
- view.backgroundColor = [UIColor clearColor];
-
- [tableView setTableFooterView:view];
- }
- #pragma mark -- 网络监控
- -(void)dealloc
- {
- [self.conn stopNotifier];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)networkStateChange
- {
- [self checkNetworkState];
- }
- - (void)checkNetworkState
- {
- // 1.检测wifi状态
- Reachability *wifi = [Reachability reachabilityForLocalWiFi];
-
- // 2.检测手机是否能上网络(WIFI\3G\2.5G)
- Reachability *conn = [Reachability reachabilityForInternetConnection];
-
- // 3.判断网络状态
- if ([wifi currentReachabilityStatus] != NotReachable)
- { // 有wifi
- NSString * str=[self getNetWorkStates];
- DLog(@"%@",str);
- if ([str isEqualToString:@"2G"]||[str isEqualToString:@"3G"])
- {
- [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境不佳,建议切换到4G网络" ToNavi:self.navigationController withColor:nil];
- }
-
-
- } else if ([conn currentReachabilityStatus] != NotReachable)
- { // 没有使用wifi, 使用手机自带网络进行上网
-
- NSString * str=[self getNetWorkStates];
- DLog(@"%@",str);
- if ([str isEqualToString:@"2G"]||[str isEqualToString:@"3G"])
- {
- [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境不佳,建议切换到4G网络" ToNavi:self.navigationController withColor:nil];
- }
-
-
- } else
- { // 没有网络
-
- [KPromptBox showKPromptBoxWithMassage:@"网络已断开,请检查网络"];
- }
- }
- - (NSString *)getNetWorkStates
- {
-
- CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
-
- if(rectStatus.size.height == 44){
-
- return @"4G";
-
- }
-
- if (iOS13) {
-
- return @"4G";
-
- }
-
- UIApplication *app = [UIApplication sharedApplication];
- NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];
- NSString *state = [[NSString alloc]init];
- int netType = 0;
- //获取到网络返回码
- for (id child in children) {
- if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
- //获取到状态栏
- netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];
-
- switch (netType) {
- case 0:
- state = @"无网络";
- _tixing.text = @"未加载出数据,请检查网络";
- //无网模式
- break;
- case 1:
- state = @"2G";
- break;
- case 2:
- state = @"3G";
- break;
- case 3:
- state = @"4G";
- break;
- case 5:
- {
- state = @"wifi";
- break;
- default:
- break;
- }
- }
- }
- //根据状态选择
- }
- return state;
- }
- @end
|