JOGetLocationViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. //
  2. // JOGetLocationViewController.m
  3. // shiku_im
  4. //
  5. // Created by 周兵 on 16/7/19.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JOGetLocationViewController.h"
  9. #import "JOPOIAnnotation.h"
  10. #import "JZLocationConverter.h"
  11. #import "Reachability.h"
  12. #import "UASLocaManager.h"
  13. @interface JOGetLocationViewController ()<MAMapViewDelegate,AMapSearchDelegate,AMapNearbySearchManagerDelegate,MKMapViewDelegate,UITableViewDataSource,UITableViewDelegate>
  14. {
  15. MAMapView *_mapView;
  16. AMapSearchAPI *_search;
  17. UITableView * _tableView;
  18. UILabel * _tixing;
  19. //两个数组
  20. NSMutableArray * _addressArr;
  21. NSMutableArray * _subAddressArr;
  22. NSMutableArray * _jinweiduArrTwo;
  23. NSMutableArray * _juliduoshaomiyuan;
  24. CGFloat lat;
  25. CGFloat loo;
  26. }
  27. @property (nonatomic, strong) Reachability *conn;//网络监控
  28. @property(strong,nonatomic)UASLocaManager *locaManager;
  29. @end
  30. @implementation JOGetLocationViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self initMapView];
  34. _addressArr=[[NSMutableArray alloc]init];
  35. _subAddressArr=[[NSMutableArray alloc]init];
  36. _jinweiduArrTwo=[[NSMutableArray alloc]init];
  37. _juliduoshaomiyuan=[[NSMutableArray alloc]init];
  38. [self initTableView];
  39. [self setNavi];
  40. _tixing=[[UILabel alloc]init];
  41. _tixing.frame=CGRectMake(self_width/2-200/2,40,200,80);
  42. _tixing.numberOfLines = 0;
  43. _tixing.text=Localized(@"UU_work_OA_punchClock_title8");
  44. _tixing.textColor=self.naviColor;
  45. _tixing.hidden=YES;
  46. [_tableView addSubview:_tixing];
  47. //监听
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kReachabilityChangedNotification object:nil];
  49. self.conn = [Reachability reachabilityForInternetConnection];
  50. [self.conn startNotifier];
  51. NSString * str=[self getNetWorkStates];
  52. if ([str isEqualToString:@"2G"]||[str isEqualToString:@"3G"])
  53. {
  54. [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境不佳,建议切换到4G网络" ToNavi:self.navigationController withColor:nil];
  55. }
  56. }
  57. - (void)setNavi
  58. {
  59. CGFloat height = 0;
  60. if (statusX) {
  61. height = 0;
  62. }
  63. UIImageView * view =[[UIImageView alloc]init];
  64. view.frame=CGRectMake(0,0,self_width,64+height);
  65. view.image = [UIImage imageNamed:@"UU_newbg2"];
  66. view.userInteractionEnabled = YES;
  67. [self.view addSubview:view];
  68. UIImageView * images=[[UIImageView alloc]initWithFrame:CGRectMake(15, 30+height, 22, 22)];
  69. images.image=[UIImage imageNamed:@"icon_back_nor3"];
  70. [view addSubview:images];
  71. UIButton * quxiao=[UIButton buttonWithType:UIButtonTypeCustom];
  72. quxiao.frame=CGRectMake(0,0+height,64,64);
  73. //[quxiao setImage:[UIImage imageNamed:@"nav_btn_back"] forState:UIControlStateNormal];
  74. [quxiao setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  75. [quxiao addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
  76. [view addSubview:quxiao];
  77. UILabel * titleLabel=[[UILabel alloc]init];
  78. titleLabel.frame=CGRectMake((self_width-200)/2,30+height, 200,24);
  79. titleLabel.text=Localized(@"UU_work_OA_punchClock_addressLittechange");
  80. titleLabel.textAlignment=1;
  81. titleLabel.textAlignment = NSTextAlignmentCenter;
  82. titleLabel.font=YBLBFont(16);
  83. titleLabel.textColor=[UIColor whiteColor];
  84. [view addSubview:titleLabel];
  85. }
  86. - (void)fanhui
  87. {
  88. [self dismissViewControllerAnimated:YES completion:^{
  89. }];
  90. }
  91. - (void)initTableView
  92. {
  93. _tableView=[[UITableView alloc]init];
  94. _tableView.frame=CGRectMake(0,(self_height-64)/2+64,self_width,(self_height-64)/2);
  95. _tableView.dataSource=self;
  96. _tableView.delegate=self;
  97. [self setExtraCellLineHidden:_tableView];
  98. [self.view addSubview:_tableView];
  99. }
  100. - (void)initMapView
  101. {
  102. CGFloat height = 0;
  103. if (statusX) {
  104. height = 0;
  105. }
  106. __weak typeof(JOGetLocationViewController) *weakSelf = self;
  107. self.locaManager = [[UASLocaManager alloc]initWithMapviewLocationUpdate:^(UASUserLocation *location, NSError *error) {
  108. __strong typeof(JOGetLocationViewController) *strongSelf = weakSelf;
  109. if (!strongSelf) {
  110. return;
  111. }
  112. strongSelf->lat=location.location.coordinate.latitude;
  113. strongSelf->loo=location.location.coordinate.longitude;
  114. [strongSelf initSearch];
  115. }];
  116. self.locaManager.mapView.frame = CGRectMake(0,64+height,self_width,(self_height-64)/2);
  117. self.locaManager.updateDistance = 10;
  118. [self.view addSubview:self.locaManager.mapView];
  119. //
  120. // if ([UASUserInfo shareManager].inRegion) {//区域内地图
  121. //
  122. // _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0,64+height,self_width,(self_height-64)/2)];
  123. //
  124. // _mapView.delegate = self;
  125. // // 不显示罗盘
  126. // _mapView.showsCompass = NO;
  127. // // 不显示比例尺
  128. // _mapView.showsScale = NO;
  129. // // 地图缩放等级
  130. // [_mapView setZoomLevel:16.1 animated:YES];
  131. // [_mapView setZoomEnabled:YES];
  132. // // 开启定位
  133. // _mapView.showsUserLocation = YES;
  134. //
  135. //
  136. // [self.view addSubview:_mapView];
  137. //
  138. // }else{//区域外地图
  139. //
  140. // self.mkMapView = [[MKMapView alloc]initWithFrame:CGRectMake(0,64+height,self_width,(self_height-64)/2)];
  141. //
  142. // self.mkMapView.delegate = self;
  143. //
  144. // self.mkMapView.showsCompass = NO;
  145. //
  146. // self.mkMapView.showsScale = NO;
  147. //
  148. // [self.mkMapView setZoomEnabled:YES];
  149. //
  150. // self.mkMapView.showsUserLocation = YES;
  151. //
  152. // [self.view addSubview:self.mkMapView];
  153. //
  154. //
  155. // }
  156. }
  157. //- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
  158. //
  159. //
  160. // [self.mkMapView setCenterCoordinate:userLocation.coordinate zoomLevel:16 animated:0];
  161. //
  162. // lat=userLocation.coordinate.latitude;
  163. // loo=userLocation.coordinate.longitude;
  164. //
  165. // [self initSearch];
  166. //
  167. //}
  168. /**
  169. 当位置更新时,会进定位回调,通过回调函数,能获取到定位点的经纬度坐标
  170. */
  171. - (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
  172. updatingLocation:(BOOL)updatingLocation
  173. {
  174. if(updatingLocation)
  175. {
  176. [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude) animated:YES];
  177. lat=userLocation.coordinate.latitude;
  178. loo=userLocation.coordinate.longitude;
  179. [self initSearch];
  180. }
  181. }
  182. - (void)initSearch
  183. {
  184. CLLocation *location = [[CLLocation alloc]initWithLatitude:lat longitude:loo];
  185. __weak typeof(JOGetLocationViewController) *weakSelf = self;
  186. [self.locaManager searchNearbyPlace:location distance:500 completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
  187. __strong typeof(JOGetLocationViewController) *strongSelf = weakSelf;
  188. if (!strongSelf) {
  189. return;
  190. }
  191. if(result.count == 0)
  192. {
  193. return;
  194. }
  195. if (strongSelf->_jinweiduArrTwo.count>0)
  196. {
  197. return;
  198. }
  199. [strongSelf->_juliduoshaomiyuan removeAllObjects];
  200. [strongSelf->_addressArr removeAllObjects];
  201. [strongSelf->_subAddressArr removeAllObjects];
  202. [strongSelf->_jinweiduArrTwo removeAllObjects];
  203. NSMutableArray * empArray=[[NSMutableArray alloc]init];
  204. for (int i=1; i<result.count; i++)
  205. {
  206. AMapPOI * m = result[i];
  207. if (strongSelf.jingweiduArray.count==3)
  208. {
  209. int juli=[strongSelf calculateDistence:[[CLLocation alloc]initWithLatitude:m.location.latitude longitude:m.location.longitude]];
  210. if (juli<[strongSelf.jingweiduArray[0] integerValue])
  211. {
  212. [empArray addObject:[NSString stringWithFormat:@"%d",juli]];
  213. [strongSelf->_juliduoshaomiyuan addObject:[NSString stringWithFormat:@"%d",juli]];
  214. [strongSelf->_addressArr addObject:m.name];
  215. [strongSelf->_subAddressArr addObject:[NSString stringWithFormat:@"%@%@%@%@",m.province,m.city,m.district,m.address]];
  216. [strongSelf->_jinweiduArrTwo addObject:m.location];
  217. }
  218. //剔除超出范围地点
  219. }
  220. else
  221. {
  222. [strongSelf->_addressArr addObject:m.name];
  223. [strongSelf->_subAddressArr addObject:[[[m.province stringByAppendingString:m.city] stringByAppendingString:m.district] stringByAppendingString:m.address]];
  224. [strongSelf->_jinweiduArrTwo addObject:m.location];
  225. }
  226. }
  227. //刷新之前进行排序
  228. if (strongSelf.jingweiduArray.count==3)
  229. {
  230. [strongSelf buddleSort:empArray];
  231. }
  232. [strongSelf->_tableView reloadData];
  233. if (strongSelf->_addressArr.count==0)
  234. {
  235. strongSelf->_tixing.hidden=NO;
  236. }
  237. }];
  238. // if ([UASUserInfo shareManager].inRegion) {
  239. //
  240. // _search = [[AMapSearchAPI alloc] init];
  241. // _search.delegate = self;
  242. //
  243. // //构造AMapPOIAroundSearchRequest对象,设置周边请求参数
  244. // AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
  245. // request.location = [AMapGeoPoint locationWithLatitude:lat longitude:loo];
  246. // request.keywords = @"";
  247. //
  248. // request.types = @"汽车服务|汽车销售|汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|医疗保健服务|住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施";
  249. // //设置微调距离
  250. // request.radius=500;
  251. // if ([self.type isEqualToString:@"waiqingqiandao"])
  252. // {
  253. // NSUserDefaults * user=[NSUserDefaults standardUserDefaults];
  254. // NSString * duoshaomiya=[NSString stringWithFormat:@"%@",[user objectForKey:@"woyaocunduoshaomi"]];
  255. // DLog(@"%@",duoshaomiya);
  256. //// if ([duoshaomiya isEqualToString:@"500"])
  257. //// {
  258. //// request.radius=500;
  259. //// }else if ([duoshaomiya isEqualToString:@"200"])
  260. //// {
  261. //// request.radius=200;
  262. ////
  263. //// }else if ([duoshaomiya isEqualToString:@"50"])
  264. //// {
  265. //// request.radius=50;
  266. //// }
  267. // request.radius = [duoshaomiya integerValue];
  268. // }
  269. // // DLog(@"设置外勤范围:%ld",(long)request.radius);
  270. //
  271. // request.sortrule = 0;
  272. // request.requireExtension = YES;
  273. // request.requireSubPOIs=YES;
  274. // //发起周边搜索
  275. // [_search AMapPOIAroundSearch: request];
  276. //
  277. // }else{
  278. //
  279. // [_juliduoshaomiyuan removeAllObjects];
  280. // [_addressArr removeAllObjects];
  281. // [_subAddressArr removeAllObjects];
  282. // [_jinweiduArrTwo removeAllObjects];
  283. //
  284. // MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
  285. // request.naturalLanguageQuery = @"地名|餐饮|银行";
  286. // request.region = self.mkMapView.region;
  287. // MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
  288. // [search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
  289. //
  290. //
  291. // NSMutableArray * empArray=[[NSMutableArray alloc]init];
  292. // for (MKMapItem *item in response.mapItems)
  293. // {
  294. //
  295. // NSString *location = [NSString stringWithFormat:@"%@%@%@%@%@%@",item.placemark.country,item.placemark.subLocality,item.placemark.locality,item.placemark.thoroughfare,item.placemark.thoroughfare,item.placemark.name];
  296. //
  297. // if (self.jingweiduArray.count==3)
  298. // {
  299. //
  300. // int juli=[self calculateDistence:item.placemark.location];
  301. //
  302. // if (juli<[self.jingweiduArray[0] integerValue])
  303. // {
  304. //
  305. // [empArray addObject:[NSString stringWithFormat:@"%d",juli]];
  306. // [_juliduoshaomiyuan addObject:[NSString stringWithFormat:@"%d",juli]];
  307. // [_addressArr addObject:item.name];
  308. // AMapGeoPoint *point = [AMapGeoPoint locationWithLatitude:item.placemark.location.coordinate.latitude longitude:item.placemark.location.coordinate.longitude];
  309. // [_subAddressArr addObject:location];
  310. // [_jinweiduArrTwo addObject:point];
  311. //
  312. // }
  313. // //剔除超出范围地点
  314. //
  315. // }
  316. // else
  317. // {
  318. //
  319. // [_addressArr addObject:item.name];
  320. // [_subAddressArr addObject:location];
  321. // AMapGeoPoint *point = [AMapGeoPoint locationWithLatitude:item.placemark.location.coordinate.latitude longitude:item.placemark.location.coordinate.longitude];
  322. // [_jinweiduArrTwo addObject:point];
  323. //
  324. // }
  325. //
  326. //
  327. //
  328. // }
  329. //
  330. // //刷新之前进行排序
  331. // if (self.jingweiduArray.count==3)
  332. // {
  333. //
  334. // [self buddleSort:empArray];
  335. //
  336. // }
  337. //
  338. //
  339. // [_tableView reloadData];
  340. //
  341. // if (_addressArr.count==0)
  342. // {
  343. // _tixing.hidden=NO;
  344. // }
  345. //
  346. //
  347. // }];
  348. //
  349. // }
  350. }
  351. - (void)setSelectedLocationWithLocation:(AMapPOI *)poi
  352. {
  353. [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(poi.location.latitude,poi.location.longitude) animated:NO];
  354. }
  355. //实现POI搜索对应的回调函数
  356. - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
  357. {
  358. if(response.pois.count == 0)
  359. {
  360. return;
  361. }
  362. if (_jinweiduArrTwo.count>0)
  363. {
  364. return;
  365. }
  366. [_juliduoshaomiyuan removeAllObjects];
  367. [_addressArr removeAllObjects];
  368. [_subAddressArr removeAllObjects];
  369. [_jinweiduArrTwo removeAllObjects];
  370. NSMutableArray * empArray=[[NSMutableArray alloc]init];
  371. for (int i=1; i<response.pois.count; i++)
  372. {
  373. AMapPOI * m=response.pois[i];
  374. if (self.jingweiduArray.count==3)
  375. {
  376. int juli=[self calculateDistence:[[CLLocation alloc]initWithLatitude:m.location.latitude longitude:m.location.longitude]];
  377. if (juli<[self.jingweiduArray[0] integerValue])
  378. {
  379. [empArray addObject:[NSString stringWithFormat:@"%d",juli]];
  380. [_juliduoshaomiyuan addObject:[NSString stringWithFormat:@"%d",juli]];
  381. [_addressArr addObject:m.name];
  382. [_subAddressArr addObject:[NSString stringWithFormat:@"%@%@%@%@",m.province,m.city,m.district,m.address]];
  383. [_jinweiduArrTwo addObject:m.location];
  384. }
  385. //剔除超出范围地点
  386. }
  387. else
  388. {
  389. [_addressArr addObject:m.name];
  390. [_subAddressArr addObject:[[[m.province stringByAppendingString:m.city] stringByAppendingString:m.district] stringByAppendingString:m.address]];
  391. [_jinweiduArrTwo addObject:m.location];
  392. }
  393. }
  394. //刷新之前进行排序
  395. if (self.jingweiduArray.count==3)
  396. {
  397. [self buddleSort:empArray];
  398. }
  399. [_tableView reloadData];
  400. if (_addressArr.count==0)
  401. {
  402. _tixing.hidden=NO;
  403. }
  404. }
  405. #pragma - mark 冒泡排序
  406. - (void)buddleSort:(NSMutableArray *)array
  407. {
  408. //DLog(@"里面时多少%@",array);
  409. for (int i = 1; i < array.count; i++)
  410. {
  411. for (int j = 0; j < array.count - i; j++)
  412. {
  413. if ([array[j] intValue] > [array[j+1] intValue])
  414. {
  415. [array exchangeObjectAtIndex:j withObjectAtIndex:j+1];
  416. [_juliduoshaomiyuan exchangeObjectAtIndex:j withObjectAtIndex:j+1];
  417. [_addressArr exchangeObjectAtIndex:j withObjectAtIndex:j+1];
  418. [_subAddressArr exchangeObjectAtIndex:j withObjectAtIndex:j+1];
  419. [_jinweiduArrTwo exchangeObjectAtIndex:j withObjectAtIndex:j+1];
  420. }
  421. }
  422. }
  423. DLog(@"排序%@",array);
  424. // for (int i=0; i<_juliduoshaomiyuan.count; i++)
  425. // {
  426. // if ([_juliduoshaomiyuan[i] integerValue]<10)
  427. // {
  428. // [_juliduoshaomiyuan exchangeObjectAtIndex:0 withObjectAtIndex:i];
  429. // [_addressArr exchangeObjectAtIndex:0 withObjectAtIndex:i];
  430. // [_subAddressArr exchangeObjectAtIndex:0 withObjectAtIndex:i];
  431. // [_jinweiduArr exchangeObjectAtIndex:0 withObjectAtIndex:i];
  432. // }
  433. // }
  434. }
  435. - (CGFloat)calculateDistence:(CLLocation *)point
  436. {
  437. CLLocationDistance distance = 0;
  438. CGFloat jingwdu=[self.jingweiduArray[1] doubleValue];
  439. CGFloat weidu=[self.jingweiduArray[2] doubleValue];
  440. if ([UASUserInfo shareManager].inRegion) {
  441. MAMapPoint point1 = MAMapPointForCoordinate(CLLocationCoordinate2DMake(point.coordinate.latitude,point.coordinate.longitude));
  442. MAMapPoint point2 = MAMapPointForCoordinate([JZLocationConverter changeBaiduCoordinateToCOMMON:CLLocationCoordinate2DMake(weidu,jingwdu)]);
  443. distance = MAMetersBetweenMapPoints(point1,point2);
  444. }else{
  445. CLLocation *loca1 = [[CLLocation alloc]initWithLatitude:point.coordinate.latitude longitude:point.coordinate.longitude];
  446. CLLocation *loca2 = [[CLLocation alloc]initWithLatitude:weidu longitude:jingwdu];;
  447. distance = [loca1 distanceFromLocation:loca2];
  448. // MKMapPoint point1 = MKMapPointMake(point.coordinate.latitude, point.coordinate.longitude);
  449. //
  450. // MKMapPoint point2 = MKMapPointMake(weidu, jingwdu);
  451. //
  452. // distance = MKMetersBetweenMapPoints(point1, point2);
  453. }
  454. return distance;
  455. }
  456. #pragma mark - tableView展示区域
  457. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  458. return 1;
  459. }
  460. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  461. return _addressArr.count;
  462. }
  463. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  464. {
  465. return 50;
  466. }
  467. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  468. //1.cell初始化
  469. static NSString *identifier = @"cell";
  470. UITableViewCell * cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  471. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
  472. UILabel * bigLabel=[[UILabel alloc]init];
  473. bigLabel.frame=CGRectMake(10,3,self_width-40,20);
  474. bigLabel.font=FONT_SIZE(13);
  475. bigLabel.textColor=[UIColor blackColor];
  476. if (_addressArr.count>indexPath.row) {
  477. bigLabel.text=_addressArr[indexPath.row];
  478. }
  479. [cell.contentView addSubview:bigLabel];
  480. UILabel * subLabel=[[UILabel alloc]init];
  481. subLabel.frame=CGRectMake(10,20,self_width-40,30);
  482. subLabel.font=FONT_SIZE(11);
  483. subLabel.numberOfLines = 0;
  484. subLabel.textColor=Color(160,160,160,1.0);
  485. if (_subAddressArr.count > indexPath.row) {
  486. subLabel.text=[NSString stringWithFormat:@"%@",_subAddressArr[indexPath.row]];
  487. }
  488. [cell.contentView addSubview:subLabel];
  489. if (self.jingweiduArray.count==3)
  490. {
  491. UILabel * juliLabel=[[UILabel alloc]init];
  492. juliLabel.frame=CGRectMake(self_width-60,5,50,20);
  493. juliLabel.font=FONT_SIZE(12);
  494. juliLabel.textColor=Color(160,160,160,1.0);
  495. juliLabel.textAlignment=1;
  496. if (_juliduoshaomiyuan.count > indexPath.row) {
  497. juliLabel.text=[NSString stringWithFormat:@"%@%@",_juliduoshaomiyuan[indexPath.row],Localized(@"UU_work_OA_punchClock_rice")];
  498. }
  499. [cell.contentView addSubview:juliLabel];
  500. }
  501. return cell;
  502. }
  503. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  504. {
  505. if (self.jingweiduArray.count==3)
  506. {
  507. [self dismissViewControllerAnimated:YES completion:^{
  508. if ([UASUserInfo shareManager].inRegion) {
  509. AMapGeoPoint * p=_jinweiduArrTwo[indexPath.row];
  510. NSString * str1=[NSString stringWithFormat:@"%f",p.latitude];
  511. NSString * str2=[NSString stringWithFormat:@"%f",p.longitude];
  512. NSString * str3=[NSString stringWithFormat:@"%@",_juliduoshaomiyuan[indexPath.row]];
  513. NSArray * arr=[NSArray arrayWithObjects:str1,str2,str3,nil];
  514. self.selectName(_addressArr[indexPath.row],_subAddressArr[indexPath.row],arr);
  515. }else{
  516. CLLocation * p=_jinweiduArrTwo[indexPath.row];
  517. NSString * str1=[NSString stringWithFormat:@"%f",p.coordinate.latitude];
  518. NSString * str2=[NSString stringWithFormat:@"%f",p.coordinate.longitude];
  519. NSString * str3=[NSString stringWithFormat:@"%@",_juliduoshaomiyuan[indexPath.row]];
  520. NSArray * arr=[NSArray arrayWithObjects:str1,str2,str3,nil];
  521. self.selectName(_addressArr[indexPath.row],_subAddressArr[indexPath.row],arr);
  522. }
  523. }];
  524. }
  525. else
  526. {
  527. [self dismissViewControllerAnimated:YES completion:^{
  528. AMapGeoPoint * p=_jinweiduArrTwo[indexPath.row];
  529. NSString * str1=[NSString stringWithFormat:@"%f",p.latitude];
  530. NSString * str2=[NSString stringWithFormat:@"%f",p.longitude];
  531. NSArray * arr=[NSArray arrayWithObjects:str1,str2,nil];
  532. self.selectName(_addressArr[indexPath.row],_subAddressArr[indexPath.row],arr);
  533. }];
  534. }
  535. }
  536. - (void)backname:(backAddress)name
  537. {
  538. self.selectName=name;
  539. }
  540. /**
  541. 去掉分割线
  542. */
  543. - (void)setExtraCellLineHidden: (UITableView *)tableView
  544. {
  545. UIView *view = [UIView new];
  546. view.backgroundColor = [UIColor clearColor];
  547. [tableView setTableFooterView:view];
  548. }
  549. #pragma mark -- 网络监控
  550. -(void)dealloc
  551. {
  552. [self.conn stopNotifier];
  553. [[NSNotificationCenter defaultCenter] removeObserver:self];
  554. }
  555. - (void)networkStateChange
  556. {
  557. [self checkNetworkState];
  558. }
  559. - (void)checkNetworkState
  560. {
  561. // 1.检测wifi状态
  562. Reachability *wifi = [Reachability reachabilityForLocalWiFi];
  563. // 2.检测手机是否能上网络(WIFI\3G\2.5G)
  564. Reachability *conn = [Reachability reachabilityForInternetConnection];
  565. // 3.判断网络状态
  566. if ([wifi currentReachabilityStatus] != NotReachable)
  567. { // 有wifi
  568. NSString * str=[self getNetWorkStates];
  569. DLog(@"%@",str);
  570. if ([str isEqualToString:@"2G"]||[str isEqualToString:@"3G"])
  571. {
  572. [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境不佳,建议切换到4G网络" ToNavi:self.navigationController withColor:nil];
  573. }
  574. } else if ([conn currentReachabilityStatus] != NotReachable)
  575. { // 没有使用wifi, 使用手机自带网络进行上网
  576. NSString * str=[self getNetWorkStates];
  577. DLog(@"%@",str);
  578. if ([str isEqualToString:@"2G"]||[str isEqualToString:@"3G"])
  579. {
  580. [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境不佳,建议切换到4G网络" ToNavi:self.navigationController withColor:nil];
  581. }
  582. } else
  583. { // 没有网络
  584. [KPromptBox showKPromptBoxWithMassage:@"网络已断开,请检查网络"];
  585. }
  586. }
  587. - (NSString *)getNetWorkStates
  588. {
  589. CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
  590. if(rectStatus.size.height == 44){
  591. return @"4G";
  592. }
  593. if (iOS13) {
  594. return @"4G";
  595. }
  596. UIApplication *app = [UIApplication sharedApplication];
  597. NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];
  598. NSString *state = [[NSString alloc]init];
  599. int netType = 0;
  600. //获取到网络返回码
  601. for (id child in children) {
  602. if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
  603. //获取到状态栏
  604. netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];
  605. switch (netType) {
  606. case 0:
  607. state = @"无网络";
  608. _tixing.text = @"未加载出数据,请检查网络";
  609. //无网模式
  610. break;
  611. case 1:
  612. state = @"2G";
  613. break;
  614. case 2:
  615. state = @"3G";
  616. break;
  617. case 3:
  618. state = @"4G";
  619. break;
  620. case 5:
  621. {
  622. state = @"wifi";
  623. break;
  624. default:
  625. break;
  626. }
  627. }
  628. }
  629. //根据状态选择
  630. }
  631. return state;
  632. }
  633. @end