JXLocMapVC.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. //
  2. // JXLocMapVC.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/19.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXLocMapVC.h"
  9. #import "JXLocPerImageVC.h"
  10. //#import "JXNewResumeInfoVC.h"
  11. #import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
  12. #import <BaiduMapAPI_Map/BMKMapComponent.h>//只引入所需的单个头文件
  13. #import <BaiduMapAPI_Base/BMKBaseComponent.h>
  14. //#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
  15. #import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
  16. #import "JXUserInfoVC.h"
  17. @interface JXLocMapVC ()<BMKMapViewDelegate,BMKLocationServiceDelegate>{
  18. BMKMapView * _imageMapView;
  19. BMKLocationService *_locService;
  20. }
  21. @end
  22. @implementation JXLocMapVC
  23. - (instancetype)initWithFrame:(CGRect)frame andType:(int)dataType
  24. {
  25. self = [super init];
  26. if (self) {
  27. _wait = [ATMHud sharedInstance];
  28. self.view.frame = frame;
  29. _nearbyData = [NSMutableArray new];
  30. _allAnnotationView = [NSMutableArray new];
  31. _dataType = dataType;
  32. [self customView];
  33. // [self getServerData];
  34. }
  35. return self;
  36. }
  37. - (void)dealloc{
  38. // [_nearbyData release];
  39. // [_allAnnotationView release];
  40. //
  41. // [super dealloc];
  42. _nearbyData = nil;
  43. _allAnnotationView = nil;
  44. }
  45. - (void)customView{
  46. [self initBaiduMapView];
  47. //复位
  48. _resetLoca = [[UIButton alloc]initWithFrame:CGRectMake(20,self.view.frame.size.height -40, 30, 30)];
  49. [_resetLoca setImage:[UIImage imageNamed:@"ic_greeting_checked"] forState:UIControlStateNormal];
  50. [_resetLoca addTarget:self action:@selector(resetLocation) forControlEvents:UIControlEventTouchUpInside];
  51. [self.view addSubview:_resetLoca];
  52. // [_resetLoca release];
  53. //上方的滚动条
  54. // UIView * topBackground = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 40)];
  55. // topBackground.backgroundColor = [UIColor whiteColor];
  56. // _topScrolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 40)];
  57. // _topScrolView.tag = 11;
  58. // _topScrolView.showsHorizontalScrollIndicator = NO;
  59. // _topScrolView.delegate = self;
  60. // _topScrolView.contentSize = CGSizeMake(80*9, 0);
  61. // [self.view addSubview:topBackground];
  62. // [topBackground addSubview:_topScrolView];
  63. //滚动条上面的按钮
  64. // NSArray * nameArr = @[@"Java",@"iOS",@"保姆",@"短工",@"家教",@"维修",@"买卖",@"寻物",@"交友"];
  65. // int buttonWidth = 80;
  66. // for (int i = 0; i < [nameArr count]; i ++) {
  67. // UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(i*buttonWidth, 0, buttonWidth, 38)];
  68. // [btn setTitle:[nameArr objectAtIndex:i] forState:UIControlStateNormal];
  69. // btn.tag = i+100;
  70. // [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  71. // [btn setTitleColor:OVERALL_BLUE_COLOR forState:UIControlStateSelected];
  72. // [btn addTarget:self action:@selector(topScrollBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  73. // [_topScrolView addSubview:btn];
  74. // }
  75. //滚动条下面的滚动View
  76. // _topMinView = [[UIView alloc]initWithFrame:CGRectMake(15, 38, buttonWidth -30, 2)];
  77. // _topMinView.backgroundColor = OVERALL_BLUE_COLOR;
  78. // [_topScrolView addSubview:_topMinView];
  79. //职位详情ScrollView
  80. _scrollBackground = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height + 100, JX_SCREEN_WIDTH, 100)];
  81. _resumeScrolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 100)];
  82. _resumeScrolView.tag = 12;
  83. _resumeScrolView.showsHorizontalScrollIndicator = NO;
  84. _resumeScrolView.delegate = self;
  85. _resumeScrolView.hidden = YES;//用于判断是否在可见区域
  86. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH *3, 100);
  87. _resumeScrolView.pagingEnabled = YES;
  88. [self.view addSubview:_scrollBackground];
  89. [_scrollBackground addSubview:_resumeScrolView];
  90. // [_resumeScrolView release];
  91. //创建ScrollView里面三个视图
  92. _jobDetailOne = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 100)];
  93. _jobDetailOne.tag = 1;
  94. [self creatJobDetailView:_jobDetailOne];
  95. [_resumeScrolView addSubview:_jobDetailOne];//创建视图里的所有控件
  96. // [_jobDetailOne release];
  97. _jobDetailTwo = [[UIView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH , 0, JX_SCREEN_WIDTH, 100)];
  98. _jobDetailTwo.tag = 2;
  99. [self creatJobDetailView:_jobDetailTwo];//创建视图里的所有控件
  100. [_resumeScrolView addSubview:_jobDetailTwo];
  101. // [_jobDetailTwo release];
  102. _jobDetailThree = [[UIView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH*2, 0, JX_SCREEN_WIDTH, 100)];
  103. _jobDetailThree.tag = 3;
  104. [self creatJobDetailView:_jobDetailThree];//创建视图里的所有控件
  105. [_resumeScrolView addSubview:_jobDetailThree];
  106. // [_jobDetailThree release];
  107. //放大缩小
  108. _scaleView = [[UIView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 100, self.view.frame.size.height - 40, 90, 30)];
  109. _scaleView.backgroundColor = [UIColor whiteColor];
  110. _scaleView.layer.cornerRadius = 15;
  111. _scaleView.clipsToBounds = YES;
  112. [self.view addSubview:_scaleView];
  113. // [_scaleView release];
  114. UIButton * narrowButton = [[UIButton alloc]initWithFrame:CGRectMake(15, 0, 30, 30)];
  115. [narrowButton setImage:[UIImage imageNamed:@"lose"] forState:UIControlStateNormal];
  116. narrowButton.tag = 10001;
  117. [narrowButton addTarget:self action:@selector(doScale:) forControlEvents:UIControlEventTouchUpInside];
  118. narrowButton.layer.cornerRadius = 15;
  119. narrowButton.clipsToBounds = YES;
  120. [_scaleView addSubview:narrowButton];
  121. // [narrowButton release];
  122. UIButton * enlargeButton = [[UIButton alloc]initWithFrame:CGRectMake(45, 0, 30, 30)];
  123. [enlargeButton setImage:[UIImage imageNamed:@"enlarge"] forState:UIControlStateNormal];
  124. [enlargeButton addTarget:self action:@selector(doScale:) forControlEvents:UIControlEventTouchUpInside];
  125. enlargeButton.layer.cornerRadius = 15;
  126. enlargeButton.clipsToBounds = YES;
  127. enlargeButton.tag = 10002;
  128. [_scaleView addSubview:enlargeButton];
  129. // [enlargeButton release];
  130. //当前位置图标
  131. // UIImageView * pointImage = [[UIImageView alloc]initWithFrame:CGRectMake((JX_SCREEN_WIDTH - 20) /2, (JX_SCREEN_HEIGHT - 25 +64)/2, 20, 25)];
  132. // pointImage.image = [UIImage imageNamed:@"location"];
  133. // pointImage.userInteractionEnabled = NO;
  134. // [self.view addSubview:pointImage];
  135. // [pointImage release];
  136. }
  137. -(void)creatJobDetailView:(UIView*)jobView{
  138. //白色背景
  139. UIButton * detailButton = [[UIButton alloc]initWithFrame:CGRectMake(20, 0, JX_SCREEN_WIDTH-40, 90)];
  140. [detailButton addTarget:self action:@selector(showDetailResume:) forControlEvents:UIControlEventTouchUpInside];
  141. detailButton.backgroundColor = [UIColor whiteColor];
  142. // detailButton.tag = 1000 + jobView.tag;
  143. detailButton.layer.cornerRadius = 5;
  144. detailButton.clipsToBounds = YES;
  145. [jobView addSubview:detailButton];
  146. // [detailButton release];
  147. //灰色背景
  148. // UIView * grayView = [[UIView alloc]initWithFrame:CGRectMake(20, 50, JX_SCREEN_WIDTH - 40, 40)];
  149. // grayView.backgroundColor = OVERALL_LIGHT_GRAY;
  150. // grayView.layer.cornerRadius = 5;
  151. // grayView.clipsToBounds = YES;
  152. // [jobView addSubview:grayView];
  153. // [grayView release];
  154. if (jobView.tag == 1) {
  155. //标题
  156. _titleLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, JX_SCREEN_WIDTH - 160, 20)];
  157. [jobView addSubview:_titleLabelOne];
  158. // [_titleLabelOne release];
  159. //付费方式
  160. _payLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 5, 110, 20)];
  161. _payLabelOne.textAlignment = NSTextAlignmentRight;
  162. _payLabelOne.font = [UIFont systemFontOfSize:11];
  163. [jobView addSubview:_payLabelOne];
  164. // [_payLabelOne release];
  165. //详情
  166. _detailLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(30, 28, JX_SCREEN_WIDTH - 100, 15)];
  167. _detailLabelOne.font = [UIFont systemFontOfSize:10];
  168. _detailLabelOne.numberOfLines = 2;
  169. [jobView addSubview:_detailLabelOne];
  170. // [_detailLabelOne release];
  171. //头像
  172. _headImageOne = [[UIImageView alloc]initWithFrame:CGRectMake(30, 53, 30, 30)];
  173. _headImageOne.layer.cornerRadius = 15;
  174. _headImageOne.clipsToBounds = YES;
  175. [jobView addSubview:_headImageOne];
  176. // [_headImageOne release];
  177. //昵称
  178. _nameLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(65, 60, 200, 15)];
  179. _nameLabelOne.font = [UIFont systemFontOfSize:11];
  180. [jobView addSubview:_nameLabelOne];
  181. // [_nameLabelOne release];
  182. //认证
  183. // _identImageOne = [[UIImageView alloc]initWithFrame:CGRectMake(65, 68, 15, 15)];
  184. // _identImageOne.image = [UIImage imageNamed:[JXMyTools verImgName:@"ic_website"]];
  185. // _identImageOne.layer.cornerRadius = 2;
  186. // _identImageOne.clipsToBounds = YES;
  187. // [jobView addSubview:_identImageOne];
  188. // [_identImageOne release];
  189. //信誉积分背景
  190. // _integralImageOne = [[UIImageView alloc]initWithFrame:CGRectMake(85, 68, 40, 15)];
  191. // _integralImageOne.image = [UIImage imageNamed:@"feaBtn_backImg_lightGreen"];
  192. // _integralImageOne.layer.cornerRadius = 2;
  193. // _integralImageOne.clipsToBounds = YES;
  194. // [jobView addSubview:_integralImageOne];
  195. // [_integralImageOne release];
  196. //信誉积分
  197. // _integralLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(95, 68, 30, 15)];
  198. // _integralLabelOne.font = [UIFont systemFontOfSize:13];
  199. // [jobView addSubview:_integralLabelOne];
  200. // [_integralLabelOne release];
  201. //距离
  202. _distanceLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 60, 110, 20)];
  203. _distanceLabelOne.textAlignment = NSTextAlignmentRight;
  204. _distanceLabelOne.font = [UIFont systemFontOfSize:11];
  205. [jobView addSubview:_distanceLabelOne];
  206. // [_distanceLabelOne release];
  207. }
  208. if (jobView.tag == 2) {
  209. //标题
  210. _titleLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, JX_SCREEN_WIDTH - 160, 20)];
  211. [jobView addSubview:_titleLabelTwo];
  212. // [_titleLabelTwo release];
  213. //付费方式
  214. _payLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 5, 110, 20)];
  215. _payLabelTwo.textAlignment = NSTextAlignmentRight;
  216. _payLabelTwo.font = [UIFont systemFontOfSize:11];
  217. [jobView addSubview:_payLabelTwo];
  218. // [_payLabelTwo release];
  219. //详情
  220. _detailLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(30, 28, JX_SCREEN_WIDTH - 100, 15)];
  221. _detailLabelTwo.font = [UIFont systemFontOfSize:10];
  222. _detailLabelTwo.numberOfLines = 2;
  223. [jobView addSubview:_detailLabelTwo];
  224. // [_detailLabelTwo release];
  225. //头像
  226. _headImageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(30, 53, 30, 30)];
  227. _headImageTwo.layer.cornerRadius = 15;
  228. _headImageTwo.clipsToBounds = YES;
  229. [jobView addSubview:_headImageTwo];
  230. // [_headImageTwo release];
  231. //昵称
  232. _nameLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(65, 60, 200, 15)];
  233. _nameLabelTwo.font = [UIFont systemFontOfSize:11];
  234. [jobView addSubview:_nameLabelTwo];
  235. // [_nameLabelTwo release];
  236. //认证
  237. // _identImageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(65, 68, 15, 15)];
  238. // _identImageTwo.image = [UIImage imageNamed:[JXMyTools verImgName:@"ic_website"]];
  239. // _identImageTwo.layer.cornerRadius = 2;
  240. // _identImageTwo.clipsToBounds = YES;
  241. // [jobView addSubview:_identImageTwo];
  242. //// [_identImageTwo release];
  243. // //信誉积分背景
  244. // _integralImageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(85, 68, 40, 15)];
  245. // _integralImageTwo.image = [UIImage imageNamed:@"feaBtn_backImg_lightGreen"];
  246. // _integralImageTwo.layer.cornerRadius = 2;
  247. // _integralImageTwo.clipsToBounds = YES;
  248. // [jobView addSubview:_integralImageTwo];
  249. //// [_integralImageTwo release];
  250. // //信誉积分
  251. // _integralLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(95, 68, 30, 15)];
  252. // _integralLabelTwo.font = [UIFont systemFontOfSize:13];
  253. // [jobView addSubview:_integralLabelTwo];
  254. // [_integralLabelTwo release];
  255. //距离
  256. _distanceLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 60, 110, 20)];
  257. _distanceLabelTwo.textAlignment = NSTextAlignmentRight;
  258. _distanceLabelTwo.font = [UIFont systemFontOfSize:11];
  259. [jobView addSubview:_distanceLabelTwo];
  260. // [_distanceLabelTwo release];
  261. }
  262. if (jobView.tag == 3) {
  263. //标题
  264. _titleLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, JX_SCREEN_WIDTH - 160, 20)];
  265. [jobView addSubview:_titleLabelThree];
  266. // [_titleLabelThree release];
  267. //付费方式
  268. _payLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 5, 110, 20)];
  269. _payLabelThree.textAlignment = NSTextAlignmentRight;
  270. _payLabelThree.font = [UIFont systemFontOfSize:11];
  271. [jobView addSubview:_payLabelThree];
  272. // [_payLabelThree release];
  273. //详情
  274. _detailLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(30, 28, JX_SCREEN_WIDTH - 100, 15)];
  275. _detailLabelThree.font = [UIFont systemFontOfSize:10];
  276. _detailLabelThree.numberOfLines = 2;
  277. [jobView addSubview:_detailLabelThree];
  278. // [_detailLabelThree release];
  279. //头像
  280. _headImageThree = [[UIImageView alloc]initWithFrame:CGRectMake(30, 53, 30, 30)];
  281. _headImageThree.layer.cornerRadius = 15;
  282. _headImageThree.clipsToBounds = YES;
  283. [jobView addSubview:_headImageThree];
  284. // [_headImageThree release];
  285. //昵称
  286. _nameLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(65, 60, 200, 15)];
  287. _nameLabelThree.font = [UIFont systemFontOfSize:11];
  288. [jobView addSubview:_nameLabelThree];
  289. // [_nameLabelThree release];
  290. //认证
  291. // _identImageThree = [[UIImageView alloc]initWithFrame:CGRectMake(65, 68, 15, 15)];
  292. // _identImageThree.image = [UIImage imageNamed:[JXMyTools verImgName:@"ic_website"]];
  293. // _identImageThree.layer.cornerRadius = 2;
  294. // _identImageThree.clipsToBounds = YES;
  295. // [jobView addSubview:_identImageThree];
  296. //// [_identImageThree release];
  297. // //信誉积分背景
  298. // _integralImageThree = [[UIImageView alloc]initWithFrame:CGRectMake(85, 68, 40, 15)];
  299. // _integralImageThree.image = [UIImage imageNamed:@"feaBtn_backImg_lightGreen"];
  300. // _integralImageThree.layer.cornerRadius = 2;
  301. // _integralImageThree.clipsToBounds = YES;
  302. // [jobView addSubview:_integralImageThree];
  303. //// [_integralImageThree release];
  304. // //信誉积分
  305. // _integralLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(95, 68, 30, 15)];
  306. // _integralLabelThree.font = [UIFont systemFontOfSize:13];
  307. // [jobView addSubview:_integralLabelThree];
  308. // [_integralLabelThree release];
  309. //距离
  310. _distanceLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 60, 110, 20)];
  311. _distanceLabelThree.textAlignment = NSTextAlignmentRight;
  312. _distanceLabelThree.font = [UIFont systemFontOfSize:11];
  313. [jobView addSubview:_distanceLabelThree];
  314. // [_distanceLabelThree release];
  315. }
  316. }
  317. //点击标签时,加载数据
  318. - (void)setData:(int)centerIndex{
  319. if (centerIndex == 0) {
  320. [self setOneData:centerIndex];
  321. [_resumeScrolView setContentOffset:CGPointMake(0, 0)];
  322. if ([_nearbyData count] > 1) {
  323. [self setTwoData:centerIndex +1];
  324. }
  325. }else if (centerIndex+1 < [_nearbyData count]) {
  326. [self setTwoData:centerIndex];
  327. [_resumeScrolView setContentOffset:CGPointMake(JX_SCREEN_WIDTH, 0)];
  328. [self setOneData:centerIndex -1];
  329. [self setThreeData:centerIndex +1];
  330. }else{
  331. [self setThreeData:centerIndex];
  332. [_resumeScrolView setContentOffset:CGPointMake(JX_SCREEN_WIDTH *2, 0)];
  333. [self setTwoData:centerIndex -1];
  334. }
  335. }
  336. #pragma mark ------------------填充数据------------------
  337. -(void)setOneData:(int)centerIndex{
  338. NSDictionary * dataDict = [_nearbyData objectAtIndex:centerIndex];
  339. //标题
  340. _titleLabelOne.text = dataDict[@"nickname"];
  341. //付费方式
  342. _payLabelOne.text = dataDict[@"telephone"];
  343. //详情
  344. // _detailLabelTwo.text = twoData[@"loc"][@"lat"];
  345. //头像
  346. [g_server getHeadImageSmall:[NSString stringWithFormat:@"%lld",[dataDict[@"userId"] longLongValue]] userName:dataDict[@"nickname"] imageView:_headImageOne];
  347. //昵称
  348. // _nameLabelOne.text = dataDict[@"nickname"];
  349. //距离
  350. _distanceLabelOne.text = [NSString stringWithFormat:@"%.3fkm",[g_server getLocation:[dataDict[@"loc"][@"lat"] doubleValue] longitude:[dataDict[@"loc"][@"lng"] doubleValue]]/1000];
  351. }
  352. -(void)setTwoData:(int)centerIndex{
  353. NSDictionary * dataDict = [_nearbyData objectAtIndex:centerIndex];
  354. //标题
  355. _titleLabelTwo.text = dataDict[@"nickname"];
  356. //付费方式
  357. _payLabelTwo.text = dataDict[@"telephone"];
  358. //详情
  359. // _detailLabelTwo.text = twoData[@"loc"][@"lat"];
  360. //头像
  361. [g_server getHeadImageSmall:[NSString stringWithFormat:@"%lld",[dataDict[@"userId"] longLongValue]] userName:dataDict[@"nickname"] imageView:_headImageTwo];
  362. //昵称
  363. // _nameLabelTwo.text = twoData[@"nickname"];
  364. //距离
  365. _distanceLabelTwo.text = [NSString stringWithFormat:@"%.3fkm",[g_server getLocation:[dataDict[@"loc"][@"lat"] doubleValue] longitude:[dataDict[@"loc"][@"lng"] doubleValue]]/1000];
  366. }
  367. -(void)setThreeData:(int)centerIndex{
  368. NSDictionary * dataDict = [_nearbyData objectAtIndex:centerIndex];
  369. //标题
  370. _titleLabelThree.text = dataDict[@"nickname"];
  371. //付费方式
  372. _payLabelThree.text = dataDict[@"telephone"];
  373. //详情
  374. // _detailLabelTwo.text = twoData[@"loc"][@"lat"];
  375. //头像
  376. [g_server getHeadImageSmall:[NSString stringWithFormat:@"%lld",[dataDict[@"userId"] longLongValue]] userName:dataDict[@"nickname"] imageView:_headImageThree];
  377. //昵称
  378. // _nameLabelTwo.text = twoData[@"nickname"];
  379. //距离
  380. _distanceLabelThree.text = [NSString stringWithFormat:@"%.3fkm",[g_server getLocation:[dataDict[@"loc"][@"lat"] doubleValue] longitude:[dataDict[@"loc"][@"lng"] doubleValue]]/1000];
  381. }
  382. #pragma mark ---------------------viewDidLoad---------------------
  383. - (void)viewDidLoad {
  384. [super viewDidLoad];
  385. }
  386. -(void)viewDidAppear:(BOOL)animated{
  387. }
  388. -(void)viewWillAppear:(BOOL)animated
  389. {
  390. [_imageMapView viewWillAppear];
  391. if (_imageMapView.delegate == nil) {
  392. _imageMapView.delegate = self; //此处记得不用的时候需要置nil,否则影响内存的释放
  393. }
  394. }
  395. -(void)viewWillDisappear:(BOOL)animated
  396. {
  397. [_imageMapView viewWillDisappear];
  398. _imageMapView.delegate = nil; // 不用时,置nil
  399. }
  400. - (void)didReceiveMemoryWarning {
  401. [super didReceiveMemoryWarning];
  402. // Dispose of any resources that can be recreated.
  403. }
  404. - (void)initBaiduMapView{
  405. _imageMapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, self.view.frame.size.height)];
  406. _imageMapView.delegate = self;
  407. [self.view addSubview:_imageMapView];
  408. // [_imageMapView release];
  409. _imageMapView.zoomLevel = 13;
  410. _imageMapView.showsUserLocation = YES;
  411. // [_imageMapView updateLocationData:userLocation];
  412. //定位服务
  413. if (_locService == nil) {
  414. _locService = [[BMKLocationService alloc] init];
  415. _locService.delegate = self;
  416. [_locService setDesiredAccuracy:kCLLocationAccuracyBest];
  417. }
  418. [_locService startUserLocationService];
  419. }
  420. #pragma mark ----------------------ScrollViewDelegate----------------
  421. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  422. if (scrollView.tag == 12) {
  423. _lastContentSet = _resumeScrolView.contentOffset;
  424. _resumeScrolView.userInteractionEnabled = NO;
  425. }
  426. }
  427. -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  428. if (scrollView.tag == 12) {
  429. if (_lastContentSet.x > _resumeScrolView.contentOffset.x) {
  430. _direction = -1;//左
  431. }else{
  432. _direction = 1;//右
  433. }
  434. }
  435. }
  436. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  437. if (scrollView.tag == 12) {
  438. if (fabs(_lastContentSet.x - _resumeScrolView.contentOffset.x) < 300) {
  439. _resumeScrolView.userInteractionEnabled = YES;
  440. return;
  441. }
  442. if (_direction == -1) {
  443. _currentIndex -= 1;
  444. }else if (_direction == 1) {
  445. _currentIndex += 1;
  446. }
  447. if (_currentIndex != [_nearbyData count] -1 && _currentIndex != 0) {
  448. //设置中间view的数据
  449. [self setTwoData:_currentIndex];
  450. [_resumeScrolView setContentOffset:CGPointMake(JX_SCREEN_WIDTH, 0)];
  451. [self setOneData:_currentIndex -1];
  452. [self setThreeData:_currentIndex +1];
  453. }
  454. //动画
  455. [_lastAnnotationView cancelSelectAnimation];
  456. for ( int i = 0; i < [_allAnnotationView count]; i++) {
  457. JXLocPerImageVC * annoView = [_allAnnotationView objectAtIndex:i];
  458. if ([annoView.annotation.title intValue] == _currentIndex) {
  459. [self reAddAnnotationView:annoView];
  460. break;
  461. }
  462. }
  463. _resumeScrolView.userInteractionEnabled = YES;
  464. }
  465. }
  466. #pragma mark -----------------------获取服务器数据----------------
  467. -(void)getServerData{
  468. if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
  469. [self showLocationDeniedAlert];
  470. }else{
  471. [_wait start];
  472. [g_server nearbyUser:_search nearOnly:YES lat:self.locY lng:self.locX page:0 toView:self];
  473. }
  474. }
  475. -(void)getDataByCurrentLocation{
  476. [g_server nearbyUser:_search nearOnly:YES lat:self.locY lng:self.locX page:0 toView:self];
  477. }
  478. //位置权限被禁时,弹出提醒框
  479. - (void)showLocationDeniedAlert{
  480. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Localized(@"JX_Tip") message:Localized(@"JX_LocationDisable") delegate:self cancelButtonTitle:Localized(@"JX_Cencal") otherButtonTitles:Localized(@"JX_Confirm"), nil];
  481. [alertView show];
  482. // [alertView release];
  483. }
  484. #pragma mark BMKLocationServiceDelegate
  485. - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
  486. {
  487. //定位到当前位置
  488. CLLocationCoordinate2D coor;
  489. if (self.locX == 0 && self.locY ==0) {
  490. if (userLocation.location == nil) {
  491. [g_App showAlert:Localized(@"JXLoc_StartLocNotice")];
  492. return;
  493. }
  494. self.locX = userLocation.location.coordinate.longitude;
  495. self.locY = userLocation.location.coordinate.latitude;
  496. coor = userLocation.location.coordinate;
  497. }else{
  498. coor = (CLLocationCoordinate2D){self.locY,self.locX};
  499. }
  500. self.locX = userLocation.location.coordinate.longitude;
  501. self.locY = userLocation.location.coordinate.latitude;
  502. //表示一个经纬度区域
  503. BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(coor, BMKCoordinateSpanMake(0.0001f,0.0001f));
  504. BMKCoordinateRegion adjustedRegion = [_imageMapView regionThatFits:viewRegion];
  505. [_imageMapView setRegion:adjustedRegion animated:YES];
  506. [_locService stopUserLocationService];
  507. [self getServerData];
  508. }
  509. #pragma mark BMKMapViewDelegate
  510. - (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
  511. {
  512. CLLocationCoordinate2D mapCoordinate= mapView.getMapStatus.targetGeoPt;
  513. NSLog(@"locX: %f locY: %f, long: %f lat: %f",_locX,_locY,mapCoordinate.longitude,mapCoordinate.latitude);
  514. if (fabs(self.locX-mapCoordinate.longitude) > 0.0001 || fabs(self.locY-mapCoordinate.latitude) > 0.0001) {
  515. self.locX = mapCoordinate.longitude;
  516. self.locY = mapCoordinate.latitude;
  517. [g_server nearbyUser:_search nearOnly:YES lat:mapCoordinate.latitude lng:mapCoordinate.longitude page:0 toView:self];
  518. }
  519. }
  520. #pragma mark -----------------自定义view覆盖物--------------
  521. -(void)addPointAnnotation{
  522. [_imageMapView removeAnnotations:_imageMapView.annotations];
  523. if (_nearbyData.count == 0) {
  524. return;
  525. }
  526. for (int i = 0 ; i < [_nearbyData count]; i++) {
  527. [self creatAnnotation:i];
  528. }
  529. }
  530. -(void)creatAnnotation:(int)i{
  531. NSDictionary * dict = [_nearbyData objectAtIndex:i];
  532. BMKPointAnnotation * pointAnnotation = [[BMKPointAnnotation alloc]init];
  533. CLLocationCoordinate2D coor = {0,0};
  534. coor.latitude = [dict[@"loc"][@"lat"] doubleValue];
  535. coor.longitude = [dict[@"loc"][@"lng"] doubleValue];
  536. // NSLog(@"annotcoor-> %d %f %f",i,[dict[@"loc"][@"lat"] doubleValue],[dict[@"loc"][@"lng"] doubleValue]);
  537. pointAnnotation.coordinate = coor;
  538. pointAnnotation.title = [NSString stringWithFormat:@"%d",i];
  539. pointAnnotation.subtitle = @"NO";//是否被点击
  540. [_imageMapView addAnnotation:pointAnnotation];
  541. }
  542. -(BMKPointAnnotation *)copyAnnotation:(BMKPointAnnotation*)pointAnnotation{
  543. BMKPointAnnotation * copyAnnotation = [[BMKPointAnnotation alloc]init];
  544. copyAnnotation.coordinate = pointAnnotation.coordinate;
  545. copyAnnotation.title = pointAnnotation.title;
  546. copyAnnotation.subtitle = pointAnnotation.subtitle;
  547. return copyAnnotation;
  548. }
  549. #pragma mark ----------------anntation生成对应的View------------------
  550. - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
  551. {
  552. //创建AnnotationView
  553. NSString *AnnotationViewID = @"ClusterMark";
  554. JXLocPerImageVC *annotationView = [[JXLocPerImageVC alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
  555. _lastAnnotationView = annotationView;
  556. [_allAnnotationView addObject:annotationView];
  557. annotationView.frame = CGRectMake(0, 0, 0, 0);
  558. // annotationView.canShowCallout = YES;//在点击大头针的时候会弹出那个黑框框
  559. annotationView.draggable = NO;//禁止标注在地图上拖动
  560. annotationView.annotation = annotation;
  561. [annotationView setData:[_nearbyData objectAtIndex:[annotation.title intValue]] andType:self.dataType];
  562. if ([annotationView.annotation.subtitle isEqualToString:@"YES"]) {
  563. [annotationView selectAnimation];
  564. }
  565. return annotationView;
  566. }
  567. -(void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
  568. NSLog(@"didSelectAnnotationView");
  569. //清除上一个放大的标签
  570. if (_lastAnnotationView) {
  571. BMKPointAnnotation * anno = _lastAnnotationView.annotation;
  572. anno.subtitle = @"NO";
  573. [_lastAnnotationView cancelSelectAnimation];
  574. }
  575. //获取被点击的序列号
  576. _currentIndex = [view.annotation.title intValue];
  577. //点击的到最前面
  578. [self reAddAnnotationView:view];
  579. //ScrollView从底部出现
  580. if (_resumeScrolView.hidden) {
  581. _resumeScrolView.hidden = NO;
  582. [UIView animateWithDuration:0.3 animations:^{
  583. _resetLoca.frame = CGRectMake(20, self.view.frame.size.height -140, 30, 30);
  584. _scrollBackground.frame = CGRectMake(0, self.view.frame.size.height - 100, JX_SCREEN_WIDTH, 100);
  585. _scaleView.frame = CGRectMake(JX_SCREEN_WIDTH -100, self.view.frame.size.height -145, 90, 30);
  586. }];
  587. }
  588. [self setData:_currentIndex];
  589. }
  590. -(void)reAddAnnotationView:(BMKAnnotationView *)view{
  591. BMKPointAnnotation * copyAnnotation = [self copyAnnotation:view.annotation];
  592. copyAnnotation.subtitle = @"YES";
  593. [_imageMapView removeAnnotation:view.annotation];
  594. [_allAnnotationView removeObject:view];
  595. [_imageMapView addAnnotation:copyAnnotation];
  596. }
  597. #pragma mark ----------------复位按钮响应事件---------------
  598. -(void)resetLocation{
  599. if (_locService.userLocation.location == nil) {
  600. [g_App showAlert:Localized(@"JXLoc_StartLocNotice")];
  601. }else{
  602. BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(_locService.userLocation.location.coordinate, BMKCoordinateSpanMake(0.0001f,0.0001f));
  603. BMKCoordinateRegion adjustedRegion = [_imageMapView regionThatFits:viewRegion];
  604. [_imageMapView setRegion:adjustedRegion animated:YES];
  605. }
  606. }
  607. -(void)doScale:(UIButton *)button{
  608. NSLog(@"doScale");
  609. if (button.tag == 10001) {
  610. [_imageMapView zoomOut];
  611. }else if(button.tag == 10002){
  612. [_imageMapView zoomIn];
  613. }
  614. }
  615. -(void)showDetailResume:(UIButton*)button{
  616. // NSLog(@"showDetailResume");
  617. NSString *jobId = nil;
  618. int version = 0;
  619. jobId = [(NSDictionary *)[_nearbyData objectAtIndex:_currentIndex] objectForKey:@"jobId"];
  620. version = [[(NSDictionary *)[_nearbyData objectAtIndex:_currentIndex] objectForKey:@"version"] intValue];
  621. NSDictionary* dict = [_nearbyData objectAtIndex:_currentIndex];
  622. // [_wait start];
  623. // [g_server getUser:[dict objectForKey:@"userId"] toView:self];
  624. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  625. vc.userId = [dict objectForKey:@"userId"];
  626. vc.fromAddType = 6;
  627. vc = [vc init];
  628. [g_navigation pushViewController:vc animated:YES];
  629. }
  630. - (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate{
  631. if (_resumeScrolView.hidden == NO) {
  632. [UIView animateWithDuration:0.3 animations:^{
  633. [self dissmissScrollView];
  634. }];
  635. }
  636. }
  637. - (void)mapView:(BMKMapView *)mapView onClickedBMKOverlayView:(BMKOverlayView *)overlayView{
  638. if (_resumeScrolView.hidden == NO) {
  639. [UIView animateWithDuration:0.3 animations:^{
  640. [self dissmissScrollView];
  641. }];
  642. }
  643. }
  644. -(void)dissmissScrollView{
  645. _scrollBackground.frame = CGRectMake(0, self.view.frame.size.height + 100, JX_SCREEN_WIDTH, 100);
  646. _resumeScrolView.hidden = YES;
  647. _resetLoca.frame = CGRectMake(20,self.view.frame.size.height -40, 30, 30);
  648. _scaleView.frame = CGRectMake(JX_SCREEN_WIDTH - 100,self.view.frame.size.height -40, 90, 30);
  649. }
  650. #pragma mark -----------------返回数据---------------------
  651. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  652. [_wait stop];
  653. if([aDownload.action isEqualToString:act_nearbyUser]){
  654. [_nearbyData removeAllObjects];
  655. [_nearbyData addObjectsFromArray:array1];
  656. [self addPointAnnotation];
  657. if ([_nearbyData count] == 1) {
  658. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, 100);
  659. }else if ([_nearbyData count] == 2){
  660. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH*2, 100);
  661. }else {
  662. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH*3, 100);
  663. }
  664. if (_resumeScrolView.hidden == NO) {
  665. [self dissmissScrollView];
  666. }
  667. }else if([aDownload.action isEqualToString:act_UserGet]){
  668. JXUserObject* user = [[JXUserObject alloc]init];
  669. [user getDataFromDict:dict];
  670. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  671. vc.user = user;
  672. vc.fromAddType = 6;
  673. vc = [vc init];
  674. // [g_window addSubview:vc.view];
  675. [g_navigation pushViewController:vc animated:YES];
  676. }
  677. }
  678. - (int)didServerResultFailed:(JXConnection *)aDownload dict:(NSDictionary *)dict{
  679. [_wait stop];
  680. return hide_error;
  681. }
  682. - (int)didServerConnectError:(JXConnection *)aDownload error:(NSError *)error{
  683. [_wait stop];
  684. return hide_error;
  685. }
  686. @end