JXGooMapVC.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. //
  2. // JXGooMapVC.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/12/6.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXGooMapVC.h"
  9. #import "UIView+ScreenShot.h"
  10. #import "JXUserInfoVC.h"
  11. #ifdef USE_GOOGLEMAP
  12. @interface JXGooMapVC ()<GMSMapViewDelegate,UIScrollViewDelegate>
  13. @property (nonatomic, strong)GMSMutableCameraPosition *camera;
  14. @property (nonatomic, strong)GMSMapView *gooMapView;
  15. @property (nonatomic, strong)GMSMarker *marker;
  16. @property (nonatomic, strong)GMSGeocoder *geocoder;
  17. @end
  18. #endif
  19. @implementation JXGooMapVC
  20. - (instancetype)initWithFrame:(CGRect)frame andType:(int)dataType
  21. {
  22. self = [super init];
  23. if (self) {
  24. #ifdef USE_GOOGLEMAP
  25. _wait = [ATMHud sharedInstance];
  26. self.view.frame = frame;
  27. _nearbyData = [NSMutableArray new];
  28. _allMarkerView = [NSMutableArray new];
  29. _dataType = dataType;
  30. _zoomLevel = 14;
  31. [self customView];
  32. // [self getServerData];
  33. #endif
  34. }
  35. return self;
  36. }
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. // Do any additional setup after loading the view, typically from a nib.
  40. #ifdef USE_GOOGLEMAP
  41. [self initGoogleMapView];
  42. #endif
  43. }
  44. #ifdef USE_GOOGLEMAP
  45. -(void)customView{
  46. //职位详情ScrollView
  47. _scrollBackground = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height + 100, JX_SCREEN_WIDTH, 100)];
  48. _resumeScrolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 100)];
  49. _resumeScrolView.tag = 12;
  50. _resumeScrolView.showsHorizontalScrollIndicator = NO;
  51. _resumeScrolView.delegate = self;
  52. _resumeScrolView.hidden = YES;//用于判断是否在可见区域
  53. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH *3, 100);
  54. _resumeScrolView.pagingEnabled = YES;
  55. [self.view addSubview:_scrollBackground];
  56. [_scrollBackground addSubview:_resumeScrolView];
  57. // [_resumeScrolView release];
  58. //创建ScrollView里面三个视图
  59. _jobDetailOne = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 100)];
  60. _jobDetailOne.tag = 1;
  61. [self creatJobDetailView:_jobDetailOne];
  62. [_resumeScrolView addSubview:_jobDetailOne];//创建视图里的所有控件
  63. // [_jobDetailOne release];
  64. _jobDetailTwo = [[UIView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH , 0, JX_SCREEN_WIDTH, 100)];
  65. _jobDetailTwo.tag = 2;
  66. [self creatJobDetailView:_jobDetailTwo];//创建视图里的所有控件
  67. [_resumeScrolView addSubview:_jobDetailTwo];
  68. // [_jobDetailTwo release];
  69. _jobDetailThree = [[UIView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH*2, 0, JX_SCREEN_WIDTH, 100)];
  70. _jobDetailThree.tag = 3;
  71. [self creatJobDetailView:_jobDetailThree];//创建视图里的所有控件
  72. [_resumeScrolView addSubview:_jobDetailThree];
  73. // [_jobDetailThree release];
  74. //放大缩小
  75. _scaleView = [[UIView alloc]initWithFrame:CGRectMake(20, self.view.frame.size.height - 40, 90, 30)];
  76. _scaleView.backgroundColor = [UIColor whiteColor];
  77. _scaleView.layer.cornerRadius = 15;
  78. _scaleView.clipsToBounds = YES;
  79. [self.view addSubview:_scaleView];
  80. // [_scaleView release];
  81. UIButton * narrowButton = [[UIButton alloc]initWithFrame:CGRectMake(15, 0, 30, 30)];
  82. [narrowButton setImage:[UIImage imageNamed:@"lose"] forState:UIControlStateNormal];
  83. narrowButton.tag = 10001;
  84. [narrowButton addTarget:self action:@selector(doScale:) forControlEvents:UIControlEventTouchUpInside];
  85. narrowButton.layer.cornerRadius = 15;
  86. narrowButton.clipsToBounds = YES;
  87. [_scaleView addSubview:narrowButton];
  88. // [narrowButton release];
  89. UIButton * enlargeButton = [[UIButton alloc]initWithFrame:CGRectMake(45, 0, 30, 30)];
  90. [enlargeButton setImage:[UIImage imageNamed:@"enlarge"] forState:UIControlStateNormal];
  91. [enlargeButton addTarget:self action:@selector(doScale:) forControlEvents:UIControlEventTouchUpInside];
  92. enlargeButton.layer.cornerRadius = 15;
  93. enlargeButton.clipsToBounds = YES;
  94. enlargeButton.tag = 10002;
  95. [_scaleView addSubview:enlargeButton];
  96. // [enlargeButton release];
  97. }
  98. -(void)initGoogleMapView{
  99. GMSCameraPosition *camera = nil;
  100. if (self.locY == 0 ) {
  101. camera = [GMSCameraPosition cameraWithLatitude:22.290664
  102. longitude:114.195304
  103. zoom:14];
  104. }else{
  105. camera = [GMSCameraPosition cameraWithLatitude:self.locY
  106. longitude:self.locX
  107. zoom:14];
  108. }
  109. _gooMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  110. _gooMapView.delegate = self;
  111. self.view = _gooMapView;
  112. _gooMapView.myLocationEnabled = YES;
  113. _gooMapView.settings.myLocationButton = YES;
  114. self.locX = _gooMapView.myLocation.coordinate.longitude;
  115. self.locY = _gooMapView.myLocation.coordinate.latitude;
  116. // GMSMarker *marker = [[GMSMarker alloc] init];
  117. // marker.position = CLLocationCoordinate2DMake(22.290664, 114.195304);
  118. // marker.title = @"香港";
  119. // marker.snippet = @"Hong Kong";
  120. // marker.map = _gooMapView;
  121. [self getServerData];
  122. }
  123. -(void)getServerData{
  124. if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
  125. [self showLocationDeniedAlert];
  126. }else{
  127. [_wait start];
  128. // searchData *search = [[searchData alloc] init];
  129. // search.minAge = 0;
  130. // search.maxAge = 200;
  131. // search.sex = -1;
  132. [g_server nearbyUser:_search nearOnly:YES lat:self.locY lng:self.locX page:0 toView:self];
  133. }
  134. }
  135. -(void)creatJobDetailView:(UIView*)jobView{
  136. //白色背景
  137. UIButton * detailButton = [[UIButton alloc]initWithFrame:CGRectMake(20, 0, JX_SCREEN_WIDTH-40, 90)];
  138. [detailButton addTarget:self action:@selector(showDetailResume:) forControlEvents:UIControlEventTouchUpInside];
  139. detailButton.backgroundColor = [UIColor whiteColor];
  140. // detailButton.tag = 1000 + jobView.tag;
  141. detailButton.layer.cornerRadius = 5;
  142. detailButton.clipsToBounds = YES;
  143. [jobView addSubview:detailButton];
  144. // [detailButton release];
  145. //灰色背景
  146. // UIView * grayView = [[UIView alloc]initWithFrame:CGRectMake(20, 50, JX_SCREEN_WIDTH - 40, 40)];
  147. // grayView.backgroundColor = [UIColor whiteColor];
  148. // grayView.layer.cornerRadius = 5;
  149. // grayView.clipsToBounds = YES;
  150. // [jobView addSubview:grayView];
  151. // [grayView release];
  152. if (jobView.tag == 1) {
  153. //标题
  154. _titleLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, JX_SCREEN_WIDTH - 160, 20)];
  155. [jobView addSubview:_titleLabelOne];
  156. // [_titleLabelOne release];
  157. //付费方式
  158. _payLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 5, 110, 20)];
  159. _payLabelOne.textAlignment = NSTextAlignmentRight;
  160. _payLabelOne.font = [UIFont systemFontOfSize:11];
  161. [jobView addSubview:_payLabelOne];
  162. // [_payLabelOne release];
  163. //详情
  164. _detailLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(30, 28, JX_SCREEN_WIDTH - 100, 15)];
  165. _detailLabelOne.font = [UIFont systemFontOfSize:10];
  166. _detailLabelOne.numberOfLines = 2;
  167. [jobView addSubview:_detailLabelOne];
  168. // [_detailLabelOne release];
  169. //头像
  170. _headImageOne = [[UIImageView alloc]initWithFrame:CGRectMake(30, 53, 30, 30)];
  171. _headImageOne.layer.cornerRadius = 15;
  172. _headImageOne.clipsToBounds = YES;
  173. [jobView addSubview:_headImageOne];
  174. // [_headImageOne release];
  175. //昵称
  176. _nameLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(65, 60, 200, 15)];
  177. _nameLabelOne.font = [UIFont systemFontOfSize:11];
  178. [jobView addSubview:_nameLabelOne];
  179. // [_nameLabelOne release];
  180. //认证
  181. // _identImageOne = [[UIImageView alloc]initWithFrame:CGRectMake(65, 68, 15, 15)];
  182. // _identImageOne.image = [UIImage imageNamed:[JXMyTools verImgName:@"ic_website"]];
  183. // _identImageOne.layer.cornerRadius = 2;
  184. // _identImageOne.clipsToBounds = YES;
  185. // [jobView addSubview:_identImageOne];
  186. //// [_identImageOne release];
  187. // //信誉积分背景
  188. // _integralImageOne = [[UIImageView alloc]initWithFrame:CGRectMake(85, 68, 40, 15)];
  189. // _integralImageOne.image = [UIImage imageNamed:@"feaBtn_backImg_lightGreen"];
  190. // _integralImageOne.layer.cornerRadius = 2;
  191. // _integralImageOne.clipsToBounds = YES;
  192. // [jobView addSubview:_integralImageOne];
  193. //// [_integralImageOne release];
  194. // //信誉积分
  195. // _integralLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(95, 68, 30, 15)];
  196. // _integralLabelOne.font = [UIFont systemFontOfSize:13];
  197. // [jobView addSubview:_integralLabelOne];
  198. // [_integralLabelOne release];
  199. //距离
  200. _distanceLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 60, 110, 20)];
  201. _distanceLabelOne.textAlignment = NSTextAlignmentRight;
  202. _distanceLabelOne.font = [UIFont systemFontOfSize:11];
  203. [jobView addSubview:_distanceLabelOne];
  204. // [_distanceLabelOne release];
  205. }
  206. if (jobView.tag == 2) {
  207. //标题
  208. _titleLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, JX_SCREEN_WIDTH - 160, 20)];
  209. [jobView addSubview:_titleLabelTwo];
  210. // [_titleLabelTwo release];
  211. //付费方式
  212. _payLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 5, 110, 20)];
  213. _payLabelTwo.textAlignment = NSTextAlignmentRight;
  214. _payLabelTwo.font = [UIFont systemFontOfSize:11];
  215. [jobView addSubview:_payLabelTwo];
  216. // [_payLabelTwo release];
  217. //详情
  218. _detailLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(30, 28, JX_SCREEN_WIDTH - 100, 15)];
  219. _detailLabelTwo.font = [UIFont systemFontOfSize:10];
  220. _detailLabelTwo.numberOfLines = 2;
  221. [jobView addSubview:_detailLabelTwo];
  222. // [_detailLabelTwo release];
  223. //头像
  224. _headImageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(30, 53, 30, 30)];
  225. _headImageTwo.layer.cornerRadius = 15;
  226. _headImageTwo.clipsToBounds = YES;
  227. [jobView addSubview:_headImageTwo];
  228. // [_headImageTwo release];
  229. //昵称
  230. _nameLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(65, 60, 200, 15)];
  231. _nameLabelTwo.font = [UIFont systemFontOfSize:11];
  232. [jobView addSubview:_nameLabelTwo];
  233. // [_nameLabelTwo release];
  234. // //认证
  235. // _identImageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(65, 68, 15, 15)];
  236. // _identImageTwo.image = [UIImage imageNamed:[JXMyTools verImgName:@"ic_website"]];
  237. // _identImageTwo.layer.cornerRadius = 2;
  238. // _identImageTwo.clipsToBounds = YES;
  239. // [jobView addSubview:_identImageTwo];
  240. //// [_identImageTwo release];
  241. // //信誉积分背景
  242. // _integralImageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(85, 68, 40, 15)];
  243. // _integralImageTwo.image = [UIImage imageNamed:@"feaBtn_backImg_lightGreen"];
  244. // _integralImageTwo.layer.cornerRadius = 2;
  245. // _integralImageTwo.clipsToBounds = YES;
  246. // [jobView addSubview:_integralImageTwo];
  247. // [_integralImageTwo release];
  248. //信誉积分
  249. // _integralLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(95, 68, 30, 15)];
  250. // _integralLabelTwo.font = [UIFont systemFontOfSize:13];
  251. // [jobView addSubview:_integralLabelTwo];
  252. // [_integralLabelTwo release];
  253. //距离
  254. _distanceLabelTwo = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 60, 110, 20)];
  255. _distanceLabelTwo.textAlignment = NSTextAlignmentRight;
  256. _distanceLabelTwo.font = [UIFont systemFontOfSize:11];
  257. [jobView addSubview:_distanceLabelTwo];
  258. // [_distanceLabelTwo release];
  259. }
  260. if (jobView.tag == 3) {
  261. //标题
  262. _titleLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, JX_SCREEN_WIDTH - 160, 20)];
  263. [jobView addSubview:_titleLabelThree];
  264. // [_titleLabelThree release];
  265. //付费方式
  266. _payLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 5, 110, 20)];
  267. _payLabelThree.textAlignment = NSTextAlignmentRight;
  268. _payLabelThree.font = [UIFont systemFontOfSize:11];
  269. [jobView addSubview:_payLabelThree];
  270. // [_payLabelThree release];
  271. //详情
  272. _detailLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(30, 28, JX_SCREEN_WIDTH - 100, 15)];
  273. _detailLabelThree.font = [UIFont systemFontOfSize:10];
  274. _detailLabelThree.numberOfLines = 2;
  275. [jobView addSubview:_detailLabelThree];
  276. // [_detailLabelThree release];
  277. //头像
  278. _headImageThree = [[UIImageView alloc]initWithFrame:CGRectMake(30, 53, 30, 30)];
  279. _headImageThree.layer.cornerRadius = 15;
  280. _headImageThree.clipsToBounds = YES;
  281. [jobView addSubview:_headImageThree];
  282. // [_headImageThree release];
  283. //昵称
  284. _nameLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(65, 60, 200, 15)];
  285. _nameLabelThree.font = [UIFont systemFontOfSize:11];
  286. [jobView addSubview:_nameLabelThree];
  287. // [_nameLabelThree release];
  288. //认证
  289. // _identImageThree = [[UIImageView alloc]initWithFrame:CGRectMake(65, 68, 15, 15)];
  290. // _identImageThree.image = [UIImage imageNamed:[JXMyTools verImgName:@"ic_website"]];
  291. // _identImageThree.layer.cornerRadius = 2;
  292. // _identImageThree.clipsToBounds = YES;
  293. // [jobView addSubview:_identImageThree];
  294. //// [_identImageThree release];
  295. // //信誉积分背景
  296. // _integralImageThree = [[UIImageView alloc]initWithFrame:CGRectMake(85, 68, 40, 15)];
  297. // _integralImageThree.image = [UIImage imageNamed:@"feaBtn_backImg_lightGreen"];
  298. // _integralImageThree.layer.cornerRadius = 2;
  299. // _integralImageThree.clipsToBounds = YES;
  300. // [jobView addSubview:_integralImageThree];
  301. //// [_integralImageThree release];
  302. // //信誉积分
  303. // _integralLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(95, 68, 30, 15)];
  304. // _integralLabelThree.font = [UIFont systemFontOfSize:13];
  305. // [jobView addSubview:_integralLabelThree];
  306. //// [_integralLabelThree release];
  307. // //距离
  308. // _distanceLabelThree = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 180 + 30, 60, 110, 20)];
  309. // _distanceLabelThree.textAlignment = NSTextAlignmentRight;
  310. // _distanceLabelThree.font = [UIFont systemFontOfSize:11];
  311. // [jobView addSubview:_distanceLabelThree];
  312. // [_distanceLabelThree release];
  313. }
  314. }
  315. //位置权限被禁时,弹出提醒框
  316. - (void)showLocationDeniedAlert{
  317. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:Localized(@"JX_Tip") message:Localized(@"JX_LocationDisable") delegate:self cancelButtonTitle:Localized(@"JX_Cencal") otherButtonTitles:Localized(@"JX_Confirm"), nil];
  318. [alertView show];
  319. // [alertView release];
  320. }
  321. #pragma mark ------------------填充数据------------------
  322. -(void)setOneData:(int)centerIndex{
  323. NSDictionary * dataDict = [_nearbyData objectAtIndex:centerIndex];
  324. //标题
  325. _titleLabelOne.text = dataDict[@"nickname"];
  326. //付费方式
  327. _payLabelOne.text = dataDict[@"telephone"];
  328. //详情
  329. // _detailLabelTwo.text = twoData[@"loc"][@"lat"];
  330. //头像
  331. [g_server getHeadImageSmall:[NSString stringWithFormat:@"%lld",[dataDict[@"userId"] longLongValue]]
  332. userName:dataDict[@"nickname"] imageView:_headImageOne];
  333. //昵称
  334. // _nameLabelOne.text = dataDict[@"nickname"];
  335. //距离
  336. _distanceLabelOne.text = [NSString stringWithFormat:@"%.3fkm",[g_server getLocation:[dataDict[@"loc"][@"lat"] doubleValue] longitude:[dataDict[@"loc"][@"lng"] doubleValue]]/1000];
  337. }
  338. -(void)setTwoData:(int)centerIndex{
  339. NSDictionary * dataDict = [_nearbyData objectAtIndex:centerIndex];
  340. //标题
  341. _titleLabelTwo.text = dataDict[@"nickname"];
  342. //付费方式
  343. _payLabelTwo.text = dataDict[@"telephone"];
  344. //详情
  345. // _detailLabelTwo.text = twoData[@"loc"][@"lat"];
  346. //头像
  347. [g_server getHeadImageSmall:[NSString stringWithFormat:@"%lld",[dataDict[@"userId"] longLongValue]] userName:dataDict[@"nickname"] imageView:_headImageTwo];
  348. //昵称
  349. // _nameLabelTwo.text = twoData[@"nickname"];
  350. //距离
  351. _distanceLabelTwo.text = [NSString stringWithFormat:@"%.3fkm",[g_server getLocation:[dataDict[@"loc"][@"lat"] doubleValue] longitude:[dataDict[@"loc"][@"lng"] doubleValue]]/1000];
  352. }
  353. -(void)setThreeData:(int)centerIndex{
  354. NSDictionary * dataDict = [_nearbyData objectAtIndex:centerIndex];
  355. //标题
  356. _titleLabelThree.text = dataDict[@"nickname"];
  357. //付费方式
  358. _payLabelThree.text = dataDict[@"telephone"];
  359. //详情
  360. // _detailLabelTwo.text = twoData[@"loc"][@"lat"];
  361. //头像
  362. [g_server getHeadImageSmall:[NSString stringWithFormat:@"%lld",[dataDict[@"userId"] longLongValue]]userName:dataDict[@"nickname"] imageView:_headImageThree];
  363. //昵称
  364. // _nameLabelTwo.text = twoData[@"nickname"];
  365. //距离
  366. _distanceLabelThree.text = [NSString stringWithFormat:@"%.3fkm",[g_server getLocation:[dataDict[@"loc"][@"lat"] doubleValue] longitude:[dataDict[@"loc"][@"lng"] doubleValue]]/1000];
  367. }
  368. #pragma mark --------------google地图事件代理GMSMapViewDelegate-------------
  369. - (void)mapView:(GMSMapView *)mapView
  370. didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
  371. NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
  372. [self dissmissScrollView];
  373. }
  374. //移动
  375. -(void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position{
  376. self.locX = position.target.longitude;
  377. self.locY = position.target.latitude;
  378. [g_server nearbyUser:_search nearOnly:YES lat:position.target.latitude lng:position.target.longitude page:0 toView:self];
  379. }
  380. - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
  381. [mapView clear];
  382. }
  383. - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker{
  384. if (_lastMarkerView == marker) {
  385. return NO;
  386. }
  387. marker.zIndex = _lastMarkerView.zIndex + 1;
  388. if (_lastMarkerView != nil) {
  389. _lastMarkerView.icon = [UIView scaleImage:_lastMarkerView.icon toScale:1/1.3];
  390. }
  391. _lastMarkerView = marker;
  392. marker.icon = [UIView scaleImage:marker.icon toScale:1.3];
  393. //ScrollView从底部出现
  394. if (_resumeScrolView.hidden) {
  395. _resumeScrolView.hidden = NO;
  396. [UIView animateWithDuration:0.3 animations:^{
  397. _scrollBackground.frame = CGRectMake(0, self.view.frame.size.height - 100, JX_SCREEN_WIDTH, 100);
  398. _scaleView.frame = CGRectMake(20, self.view.frame.size.height -145, 90, 30);
  399. }];
  400. }
  401. _currentIndex = [marker.userData intValue];
  402. [self setData:_currentIndex];
  403. return YES;
  404. }
  405. -(void)dissmissScrollView{
  406. _scrollBackground.frame = CGRectMake(0, self.view.frame.size.height + 100, JX_SCREEN_WIDTH, 100);
  407. _resumeScrolView.hidden = YES;
  408. _scaleView.frame = CGRectMake(20,self.view.frame.size.height -40, 90, 30);
  409. }
  410. #pragma mark ----------------------ScrollViewDelegate----------------
  411. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  412. if (scrollView.tag == 12) {
  413. _lastContentSet = _resumeScrolView.contentOffset;
  414. _resumeScrolView.userInteractionEnabled = NO;
  415. }
  416. }
  417. -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  418. if (scrollView.tag == 12) {
  419. if (_lastContentSet.x > _resumeScrolView.contentOffset.x) {
  420. _direction = -1;//左
  421. }else{
  422. _direction = 1;//右
  423. }
  424. }
  425. }
  426. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  427. if (scrollView.tag == 12) {
  428. if (fabs(_lastContentSet.x - _resumeScrolView.contentOffset.x) < 300) {
  429. _resumeScrolView.userInteractionEnabled = YES;
  430. return;
  431. }
  432. if (_direction == -1) {
  433. _currentIndex -= 1;
  434. }else if (_direction == 1) {
  435. _currentIndex += 1;
  436. }
  437. if (_currentIndex != [_nearbyData count] -1 && _currentIndex != 0) {
  438. //设置中间view的数据
  439. [self setTwoData:_currentIndex];
  440. [_resumeScrolView setContentOffset:CGPointMake(JX_SCREEN_WIDTH, 0)];
  441. [self setOneData:_currentIndex -1];
  442. [self setThreeData:_currentIndex +1];
  443. }
  444. [self changeSelectMarker];
  445. _resumeScrolView.userInteractionEnabled = YES;
  446. }
  447. }
  448. #pragma mark -----------------返回数据---------------------
  449. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  450. [_wait stop];
  451. if([aDownload.action isEqualToString:act_nearbyUser]){
  452. [_nearbyData removeAllObjects];
  453. [_nearbyData addObjectsFromArray:array1];
  454. // [self addPointAnnotation];
  455. [self addPointMarker];
  456. if ([_nearbyData count] == 1) {
  457. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, 100);
  458. }else if ([_nearbyData count] == 2){
  459. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH*2, 100);
  460. }else {
  461. _resumeScrolView.contentSize = CGSizeMake(JX_SCREEN_WIDTH*3, 100);
  462. }
  463. if (_resumeScrolView.hidden == NO) {
  464. [self dissmissScrollView];
  465. }
  466. }else if([aDownload.action isEqualToString:act_UserGet]){
  467. JXUserObject* user = [[JXUserObject alloc]init];
  468. [user getDataFromDict:dict];
  469. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  470. vc.user = user;
  471. vc.fromAddType = 6;
  472. vc = [vc init];
  473. // [g_window addSubview:vc.view];
  474. [g_navigation pushViewController:vc animated:YES];
  475. }
  476. }
  477. - (int)didServerResultFailed:(JXConnection *)aDownload dict:(NSDictionary *)dict{
  478. [_wait stop];
  479. return hide_error;
  480. }
  481. - (int)didServerConnectError:(JXConnection *)aDownload error:(NSError *)error{
  482. [_wait stop];
  483. return hide_error;
  484. }
  485. -(void)addPointMarker{
  486. // [_gooMapView clear];
  487. for (GMSMarker *marker in _allMarkerView) {
  488. [marker setMap:NULL];
  489. }
  490. [_allMarkerView removeAllObjects];
  491. if (_nearbyData.count == 0) {
  492. return;
  493. }
  494. for (int i = 0 ; i < [_nearbyData count]; i++) {
  495. [self creatMarker:i];
  496. }
  497. }
  498. -(void)creatMarker:(int)i{
  499. NSDictionary * dict = [_nearbyData objectAtIndex:i];
  500. GMSMarker *customMarker = [[GMSMarker alloc] init];
  501. float latitude;
  502. float longitude;
  503. latitude = [dict[@"loc"][@"lat"] doubleValue];
  504. longitude = [dict[@"loc"][@"lng"] doubleValue];
  505. customMarker.position = CLLocationCoordinate2DMake(latitude, longitude);
  506. //自定义图片view
  507. UIView * headViewBG = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 60)];
  508. headViewBG.backgroundColor = [UIColor clearColor];
  509. UIImageView * pointImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 60)];
  510. pointImage.image = [UIImage imageNamed:@"locationAcc2"];
  511. [headViewBG addSubview:pointImage];
  512. UIImageView * headImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 3, 40, 40)];
  513. headImage.layer.cornerRadius = 20;
  514. headImage.clipsToBounds = YES;
  515. [headViewBG addSubview:headImage];
  516. //头像网址
  517. NSString *userId = [NSString stringWithFormat:@"%lld",[dict[@"userId"] longLongValue]];
  518. if([userId longLongValue]<10100 && [userId longLongValue]>=10000){
  519. return;
  520. }
  521. if([userId length]<=0){
  522. headImage.image = [UIImage imageNamed:@"avatar_normal"];
  523. return;
  524. }
  525. NSString* dir = [NSString stringWithFormat:@"%lld",[userId longLongValue] % 10000];
  526. NSString* urlString = [NSString stringWithFormat:@"%@avatar/t/%@/%@.jpg",g_config.downloadAvatarUrl,dir,userId];
  527. NSURL * url = [[NSURL alloc]initWithString:urlString];
  528. [headImage sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  529. headImage.image = image;
  530. customMarker.icon = [headViewBG viewSnapshot:headViewBG withInRect:headViewBG.frame];
  531. }];
  532. customMarker.userData = @(i);
  533. customMarker.map = _gooMapView;
  534. [_allMarkerView addObject:customMarker];
  535. }
  536. -(void)getDataByCurrentLocation{
  537. [g_server nearbyUser:_search nearOnly:YES lat:self.locY lng:self.locX page:0 toView:self];
  538. }
  539. #pragma mark ----------------按钮响应事件---------------
  540. //点击标签时,加载数据
  541. - (void)setData:(int)centerIndex{
  542. if (centerIndex == 0) {
  543. [self setOneData:centerIndex];
  544. [_resumeScrolView setContentOffset:CGPointMake(0, 0)];
  545. if ([_nearbyData count] > 1) {
  546. [self setTwoData:centerIndex +1];
  547. }
  548. }else if (centerIndex+1 < [_nearbyData count]) {
  549. [self setTwoData:centerIndex];
  550. [_resumeScrolView setContentOffset:CGPointMake(JX_SCREEN_WIDTH, 0)];
  551. [self setOneData:centerIndex -1];
  552. [self setThreeData:centerIndex +1];
  553. }else{
  554. [self setThreeData:centerIndex];
  555. [_resumeScrolView setContentOffset:CGPointMake(JX_SCREEN_WIDTH *2, 0)];
  556. [self setTwoData:centerIndex -1];
  557. }
  558. }
  559. -(void)doScale:(UIButton *)button{
  560. NSLog(@"doScale");
  561. if (button.tag == 10001) {
  562. _zoomLevel -= 1;
  563. [_gooMapView animateToZoom:_zoomLevel];
  564. }else if(button.tag == 10002){
  565. _zoomLevel += 1;
  566. [_gooMapView animateToZoom:_zoomLevel];
  567. }
  568. }
  569. -(void)changeSelectMarker{
  570. _lastMarkerView.icon = [UIView scaleImage:_lastMarkerView.icon toScale:1/1.3];
  571. for ( int i = 0; i < [_allMarkerView count]; i++) {
  572. GMSMarker * markerD = [_allMarkerView objectAtIndex:i];
  573. if ([markerD.userData intValue] == _currentIndex) {
  574. markerD.icon = [UIView scaleImage:markerD.icon toScale:1.3];
  575. _lastMarkerView = markerD;
  576. }
  577. }
  578. }
  579. -(void)showDetailResume:(UIButton*)button{
  580. NSString *jobId = nil;
  581. int version = 0;
  582. jobId = [(NSDictionary *)[_nearbyData objectAtIndex:_currentIndex] objectForKey:@"jobId"];
  583. version = [[(NSDictionary *)[_nearbyData objectAtIndex:_currentIndex] objectForKey:@"version"] intValue];
  584. NSDictionary* dict = [_nearbyData objectAtIndex:_currentIndex];
  585. // [_wait start];
  586. // [g_server getUser:[dict objectForKey:@"userId"] toView:self];
  587. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  588. vc.userId = [dict objectForKey:@"userId"];
  589. vc.fromAddType = 6;
  590. vc = [vc init];
  591. [g_navigation pushViewController:vc animated:YES];
  592. }
  593. - (void)didReceiveMemoryWarning {
  594. [super didReceiveMemoryWarning];
  595. // Dispose of any resources that can be recreated.
  596. }
  597. /*
  598. #pragma mark - Navigation
  599. // In a storyboard-based application, you will often want to do a little preparation before navigation
  600. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  601. // Get the new view controller using [segue destinationViewController].
  602. // Pass the selected object to the new view controller.
  603. }
  604. */
  605. #endif
  606. @end