// // UserSignPage.m // istanbul // // Created by WindShan on 2017/6/13. // Copyright © 2017年 WindShan. All rights reserved. // #import "UserSignPage.h" #import "GloriaLabel.h" #import "MyAnimatedAnnotationView.h" #import "BaseNaviController.h" #import "HotelSelPage.h" #import "NetworkSingleton.h" #import "SignInfo.h" @interface UserSignPage () { CLLocationDegrees locateLatitude; CLLocationDegrees locateLongitude; BMKPointAnnotation* pointAnnotation; BMKPointAnnotation* animatedAnnotation; NSString * currentAdress; NSString * currentzhengmingName; NSString * currentzhengmingTel; UITextField * zhengmingNameTF; UITextField * zhengmingTelTF; GloriaLabel* addressLabel; GloriaLabel* signInTime; GloriaLabel* signOutTime; GloriaLabel* signInDistrib; GloriaLabel* signOutDistrib; UIButton * sign_in_btn; UIButton * sign_out_btn; } @property (nonatomic, strong) UITableView * tableView; @end @implementation UserSignPage - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSInteger textLength = 0; if ([string isEqualToString:@""]) { textLength = textField.text.length-1; } else { textLength = textField.text.length+1; } BOOL flag = NO; if( textField == zhengmingTelTF ) { // 检测手机号是否合法 if( textLength == 11 && [StringUtil isMobile:[zhengmingTelTF.text stringByAppendingString:string]] == NO) { [Global alertMessage:@"手机号码不合法,请重新输入!"]; } // 大于11位数不让输入 if( textLength > 11 ) return NO; } flag = YES; if (flag) { // [loginBtn setBackgroundColor:BLUECOLOR]; // loginBtn.userInteractionEnabled = YES; } else { // loginBtn.backgroundColor = [UIColor lightGrayColor]; // loginBtn.userInteractionEnabled = NO; } return flag; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isFirstResponder]) { [textField resignFirstResponder]; } return YES; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self textFieldShouldReturn:zhengmingNameTF]; [self textFieldShouldReturn:zhengmingTelTF]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] init]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.separatorColor = [UIColor clearColor]; _tableView.backgroundColor = [UIColor clearColor]; //_tableView.userInteractionEnabled = NO; [self.view addSubview:_tableView]; [_tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsMake(0 , 0, 0, 0)); }]; _tableView.tableFooterView = [UIView new]; } return _tableView; } #pragma mark - UITableViewDelegate&UITableViewDataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } //-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 0; //} // -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 5; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if( indexPath.row < 4) return 35; else return 200; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString * identifier = @"signCell"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (nil == cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } //cell.delegate = self; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.userInteractionEnabled = YES; CGFloat xxx; switch (indexPath.row) { case 0: { cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; cell.image = [UIImage imageNamed:@"icon_green_call"]; cell.text = _curHotel_Id != nil?_curHotel_Id.name:@"选择酒店"; cell.textColor = kUIColorFromRGB(0x00b744); xxx = cell.imageView.frame.origin.x; } break; case 1: { cell.image = [UIImage imageNamed:@"sign_address_tag"]; //cell.text = currentAdress; if(addressLabel==nil) { addressLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(38+10, 0, SCREEN_WIDTH-cell.textLabel.frame.origin.x, 40)]; addressLabel.font = FONT14; addressLabel.textAlignment = NSTextAlignmentLeft; addressLabel.userInteractionEnabled = NO; addressLabel.textColor = kUIColorFromRGB(0x00b744); [cell.contentView addSubview:addressLabel]; } addressLabel.text = currentAdress; } break; case 2: { cell.image = [UIImage imageNamed:@"sign_prove_tag"]; if(zhengmingNameTF==nil) { zhengmingNameTF = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-cell.textLabel.frame.origin.x, 40)]; zhengmingNameTF.font = [UIFont fontWithName:@"Arial" size:16]; zhengmingNameTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入证明人"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x6e6e6e)}]; zhengmingNameTF.delegate = self; [zhengmingNameTF setValue:kUIColorFromRGB(0x00b744) forKeyPath:@"_placeholderLabel.textColor"]; //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; zhengmingNameTF.textColor = kUIColorFromRGB(0x00b744); //zhengmingNameTF.keyboardType = UIKeyboardTypeNumberPad; zhengmingNameTF.textAlignment = NSTextAlignmentLeft; zhengmingNameTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(zhengmingNameTF.frame.origin.x,zhengmingNameTF.frame.origin.y,10.0, zhengmingNameTF.frame.size.height)]; zhengmingNameTF.leftView = blankView; zhengmingNameTF.leftViewMode =UITextFieldViewModeAlways; zhengmingNameTF.userInteractionEnabled = YES; //zhengmingNameTF.returnKeyType = UIReturnKeyDone;//改变为完成键 [cell.contentView addSubview:zhengmingNameTF]; } if(![currentzhengmingName isEqualToString:@""]) { zhengmingNameTF.text = currentzhengmingName; } } break; case 3: { cell.image = [UIImage imageNamed:@"icon_green_call"]; if(zhengmingTelTF==nil) { zhengmingTelTF = [[UITextField alloc] initWithFrame:CGRectMake(38, 0, SCREEN_WIDTH-cell.textLabel.frame.origin.x, 40)]; zhengmingTelTF.font = [UIFont fontWithName:@"Arial" size:16]; zhengmingTelTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入证明人手机号"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x6e6e6e)}]; zhengmingTelTF.delegate = self; [zhengmingTelTF setValue:kUIColorFromRGB(0x00b744) forKeyPath:@"_placeholderLabel.textColor"]; //zhengmingTelTF.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; zhengmingTelTF.textColor = kUIColorFromRGB(0x00b744); zhengmingTelTF.keyboardType = UIKeyboardTypeNumberPad; zhengmingTelTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(zhengmingTelTF.frame.origin.x,zhengmingTelTF.frame.origin.y,10.0, zhengmingTelTF.frame.size.height)]; zhengmingTelTF.leftView = blankView; zhengmingTelTF.leftViewMode =UITextFieldViewModeAlways; zhengmingTelTF.textAlignment = NSTextAlignmentLeft; //zhengmingTelTF.returnKeyType = UIReturnKeyDone;//改变为完成键 [cell.contentView addSubview:zhengmingTelTF]; } if(![currentzhengmingTel isEqualToString:@""]) { zhengmingTelTF.text = currentzhengmingTel; } } break; default: break; } cell.backgroundColor = [UIColor clearColor]; cell.alpha = 0.5; if( indexPath.row != 4) { UIView * _pline = [[UIView alloc] initWithFrame:CGRectMake(0, 35, SCREEN_WIDTH, 1)]; _pline.backgroundColor = [UIColor grayColor]; [cell.contentView addSubview:_pline]; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; [self.view endEditing:YES]; if(indexPath.row == 0) { // 跳转选择酒店 HotelSelPage* page = [[HotelSelPage alloc] initIsFirstPage:NO]; page.bSelRoom = 0; // 跳转界面 BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page]; [self presentViewController:baseNav animated:YES completion:nil]; } } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; [_mapView viewWillAppear]; _mapView.delegate = self; _locService.delegate = self; _geocodesearch.delegate = self; if(_curHotel_Id != nil) { [self getusersign]; } } -(void)viewWillDisappear:(BOOL)animated { [super viewDidDisappear:YES]; [_mapView viewWillDisappear]; _mapView.delegate = nil; // 不用时,置nil _locService.delegate = nil; _geocodesearch.delegate = nil; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.title = @"签到打卡"; [self setNavigationLeft:@"返回" sel:@selector(backAction)]; [self setNavigationRight:@"刷新" sel:@selector(startLocation)]; //适配ios7 if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) { self.navigationController.navigationBar.translucent = NO; } [self initMap]; [self startLocation]; currentzhengmingName = @""; currentAdress = @""; currentzhengmingTel = @""; self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 140); CGFloat _bottomBkH = 230; CGFloat _offW = 0; CGFloat _offH = 0; if(IsiPhone4 || IsiPhone5) { _bottomBkH = 200; _offW = 20; _offH = 15; } UIImageView * _bottomBk = [[UIImageView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-_bottomBkH, SCREEN_WIDTH, _bottomBkH)]; _bottomBk.image = [UIImage imageNamed:@"sign_user_btn_bk"]; _bottomBk.userInteractionEnabled = YES; [self.view addSubview:_bottomBk]; // 签到 UIImageView * sign_daka_bk1 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH/2-140+_offW)/2, (_bottomBkH-120)/3, 140-_offW, 120)]; sign_daka_bk1.image = [UIImage imageNamed:@"sign_daka_bk"]; sign_daka_bk1.userInteractionEnabled = YES; [_bottomBk addSubview:sign_daka_bk1]; UIImageView * sign_no_in_bk = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH/2-140+_offW)/2, -20, 94-_offW, 94-_offW)]; sign_no_in_bk.image = [UIImage imageNamed:@"sign_no_in_bk"]; [sign_daka_bk1 addSubview:sign_no_in_bk]; signInTime = [[GloriaLabel alloc] initWithFrame:CGRectMake(0, 40-_offH, 94-_offW, 40)]; signInTime.font = [UIFont boldSystemFontOfSize:14]; signInTime.textAlignment = NSTextAlignmentCenter; signInTime.textColor = [UIColor whiteColor]; signInTime.text = @"08:30"; [sign_no_in_bk addSubview:signInTime]; signInDistrib = [[GloriaLabel alloc] initWithFrame:CGRectMake(0, 60-_offH, 140-_offW, 40)]; signInDistrib.font = FONT14; signInDistrib.textAlignment = NSTextAlignmentCenter; signInDistrib.textColor = kUIColorFromRGB(0x6e6e6e); signInDistrib.text = @"首次签到"; [sign_daka_bk1 addSubview:signInDistrib]; sign_in_btn = [UIButton buttonWithType:UIButtonTypeCustom]; sign_in_btn.frame = CGRectMake((140-100-_offW)/2, 90-_offH, 100, 21); [sign_in_btn setBackgroundImage:[UIImage imageNamed:@"sign_no_btn_bk" ] forState:UIControlStateNormal]; [sign_in_btn setTitle:@"点击此处打卡" forState:UIControlStateNormal]; sign_in_btn.titleLabel.font = [UIFont systemFontOfSize: 12.0]; [sign_in_btn setTitleColor:kUIColorFromRGB(0x00b744) forState:UIControlStateNormal]; [sign_in_btn addTarget:self action:@selector(usersign_in_action) forControlEvents:UIControlEventTouchUpInside]; [sign_daka_bk1 addSubview:sign_in_btn]; // 签离 UIImageView * sign_daka_bk2 = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+(SCREEN_WIDTH/2-140+_offW)/2, (_bottomBkH-120)/3, 140-_offW, 120)]; sign_daka_bk2.image = [UIImage imageNamed:@"sign_daka_bk"]; sign_daka_bk2.userInteractionEnabled = YES; [_bottomBk addSubview:sign_daka_bk2]; UIImageView * sign_out_bk = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH/2-140+_offW)/2, -20, 94-_offW, 94-_offW)]; sign_out_bk.image = [UIImage imageNamed:@"sign_out_bk"]; [sign_daka_bk2 addSubview:sign_out_bk]; signOutTime = [[GloriaLabel alloc] initWithFrame:CGRectMake(0, 40-_offH, 94-_offW, 40)]; signOutTime.font = [UIFont boldSystemFontOfSize:14]; signOutTime.textAlignment = NSTextAlignmentCenter; signOutTime.textColor = [UIColor whiteColor]; signOutTime.text = @"17:30"; [sign_out_bk addSubview:signOutTime]; signOutDistrib = [[GloriaLabel alloc] initWithFrame:CGRectMake(0, 60-_offH, 140-_offW, 40)]; signOutDistrib.font = FONT14; signOutDistrib.textAlignment = NSTextAlignmentCenter; signOutDistrib.textColor = kUIColorFromRGB(0x6e6e6e); signOutDistrib.text = @"已签退"; [sign_daka_bk2 addSubview:signOutDistrib]; sign_out_btn = [UIButton buttonWithType:UIButtonTypeCustom]; sign_out_btn.frame = CGRectMake((140-100-_offW)/2, 90-_offH, 100, 21); [sign_out_btn setBackgroundImage:[UIImage imageNamed:@"sign_in_btn_bk" ] forState:UIControlStateNormal]; [sign_out_btn setTitle:@"已签退" forState:UIControlStateNormal]; sign_out_btn.titleLabel.font = [UIFont systemFontOfSize: 12.0]; [sign_out_btn setTitleColor:kUIColorFromRGB(0xff8b00) forState:UIControlStateNormal]; [sign_out_btn addTarget:self action:@selector(usersign_out_action) forControlEvents:UIControlEventTouchUpInside]; [sign_daka_bk2 addSubview:sign_out_btn]; signInDistrib.text = @"首次签到"; [sign_in_btn setTitle:@"点击此处打卡" forState:UIControlStateNormal]; signOutDistrib.text = @"离开签退"; [sign_out_btn setTitle:@"点击此处签退" forState:UIControlStateNormal]; } // 获取签到信息 -(void)getusersign { //params.put("userID", MainApp.userId); //params.put("hotelID", hotelid); NSString *path = [[NSString alloc] initWithFormat:GET_SIGN_INFO]; NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:[UserDefault stringForKey:@"user_id"] forKey:@"userID"]; [param setObject:_curHotel_Id._id forKey:@"hotelID"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 if(![Global isEmptyObject:resModel.content]) { NSMutableArray *modelTempArray = [SignInfo mj_objectArrayWithKeyValuesArray:resModel.content]; BASE_INFO_FUN(resModel.content); if(modelTempArray.count > 0) { for( int i = 0; i < modelTempArray.count; i++ ) { SignInfo * model = [modelTempArray objectAtIndex:i]; if(model.type == 1) { [sign_in_btn setTitle:@"已签到" forState:UIControlStateNormal]; } else if(model.type == 2) { [sign_out_btn setTitle:@"已签退" forState:UIControlStateNormal]; } } } else { signInDistrib.text = @"首次签到"; [sign_in_btn setTitle:@"点击此处签到" forState:UIControlStateNormal]; signOutDistrib.text = @"离开签退"; [sign_out_btn setTitle:@"点击此处签退" forState:UIControlStateNormal]; } [self.tableView reloadData]; //[_modelArray addObjectsFromArray:modelTempArray]; //hotelSelModel = [AdModel mj_objectWithKeyValues:resModel.content]; } else { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } } else { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } } failure:^(NSString *error) { [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self]; }]; } -(void)usersign_in_action { if(currentAdress == nil) { [Global alertMessageEx:@"定位失败,请刷新您的位置信息!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(zhengmingNameTF.text.length == 0) { [Global alertMessageEx:@"请填写证明人名字!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(zhengmingTelTF.text.length == 0) { [Global alertMessageEx:@"请填写证明人电话!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(_curHotel_Id == nil) { [Global alertMessageEx:@"请选择酒店!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { NSString *path = [[NSString alloc] initWithFormat:SIGN_IN]; NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:[UserDefault stringForKey:@"user_id"] forKey:@"userID"]; [param setObject:currentAdress forKey:@"address"]; //lat 37.785834,long -122.406417 %.8f [param setObject:[NSString stringWithFormat:@"%.8f",locateLatitude] forKey:@"lat"]; [param setObject:[NSString stringWithFormat:@"%.8f",locateLongitude] forKey:@"lng"]; [param setObject:zhengmingNameTF.text forKey:@"cert_name"]; [param setObject:zhengmingTelTF.text forKey:@"cert_tel"]; [param setObject:_curHotel_Id._id forKey:@"hotelID"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } } failure:^(NSString *error) { [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self]; }]; } } -(void)usersign_out_action { if(currentAdress == nil) { [Global alertMessageEx:@"定位失败,请刷新您的位置信息!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(zhengmingNameTF.text.length == 0) { [Global alertMessageEx:@"请填写证明人名字!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(zhengmingTelTF.text.length == 0) { [Global alertMessageEx:@"请填写证明人电话!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else if(_curHotel_Id == nil) { [Global alertMessageEx:@"请选择酒店!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { NSString *path = [[NSString alloc] initWithFormat:SIGN_OUT]; NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:[UserDefault stringForKey:@"user_id"] forKey:@"userID"]; [param setObject:currentAdress forKey:@"address"]; //lat 37.785834,long -122.406417 %.8f [param setObject:[NSString stringWithFormat:@"%.8f",locateLatitude] forKey:@"lat"]; [param setObject:[NSString stringWithFormat:@"%.8f",locateLongitude] forKey:@"lng"]; [param setObject:zhengmingNameTF.text forKey:@"cert_name"]; [param setObject:zhengmingTelTF.text forKey:@"cert_tel"]; [param setObject:_curHotel_Id._id forKey:@"hotelID"]; MPWeakSelf(self); [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody) { MPStrongSelf(self); BaseResModel * resModel = [Global toBaseModel:responseBody]; if(resModel.code == 0) { //发送成功提示 [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } else { [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; } } failure:^(NSString *error) { [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self]; }]; } } -(void) initMap { //初始化地图 _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; _mapView.showsUserLocation = YES;//显示定位图层 _mapView.showMapScaleBar=YES; _mapView.zoomLevel=18.0; _mapView.mapType = BMKMapTypeStandard; [self.view addSubview:_mapView]; // BMKLocationViewDisplayParam *param = [[BMKLocationViewDisplayParam alloc] init]; // param.accuracyCircleStrokeColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5]; // param.accuracyCircleFillColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.3]; // param.isAccuracyCircleShow =true;//精度圈是否显示 // [_mapView updateLocationViewWithParam:param]; _locService = [[BMKLocationService alloc]init]; _locService.desiredAccuracy = kCLLocationAccuracyBest; _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放 _locService.delegate = self; NSLog(@"进入普通定位态"); [_locService startUserLocationService]; _mapView.showsUserLocation = NO;//先关闭显示的定位图层 _mapView.userTrackingMode = BMKUserTrackingModeFollow;//设置定位的状态 _mapView.showsUserLocation = YES;//显示定位图层 _geocodesearch = [[BMKGeoCodeSearch alloc] init]; _geocodesearch.delegate = self; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)backAction { [self dismissViewControllerAnimated:YES completion:nil]; } -(void)startLocation { currentzhengmingTel = zhengmingTelTF.text; currentzhengmingName = zhengmingNameTF.text; [_locService startUserLocationService]; _mapView.showsUserLocation = NO; _mapView.userTrackingMode = BMKUserTrackingModeFollow; _mapView.showsUserLocation = YES; } //停止定位 -(void)stopLocation { [_locService stopUserLocationService]; _mapView.showsUserLocation = YES;//显示定位图层 } -(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error { NSLog(@"address:%@----%@",result.addressDetail,result.address); currentAdress = result.address; [self.tableView reloadData]; [self stopLocation]; //[locateAddressLabel setText:[NSString stringWithFormat:@"地址:%@",result.address]]; //addressDetail: 层次化地址信息 //address: 地址名称 //businessCircle: 商圈名称 // location: 地址坐标 // poiList: 地址周边POI信息,成员类型为BMKPoiInfo } #pragma mark - Navigation /** *在地图View将要启动定位时,会调用此函数 *@param mapView 地图View */ - (void)willStartLocatingUser { NSLog(@"start locate"); } /** *用户方向更新后,会调用此函数 *@param userLocation 新的用户位置 */ //- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation //{ // [_mapView updateLocationData:userLocation]; // NSLog(@"heading is %@",userLocation.heading); // locateLatitude = userLocation.location.coordinate.latitude; // locateLongitude = userLocation.location.coordinate.longitude; //[latitudeLabel setText:[NSString stringWithFormat:@"经度:%lf",userLocation.location.coordinate.longitude]]; //[longitudeLabel setText:[NSString stringWithFormat:@"纬度:%lf",userLocation.location.coordinate.latitude]]; //[_mapView updateLocationData:userLocation]; //_mapView.centerCoordinate = userLocation.location.coordinate; //更新当前位置到地图中间 //地理反编码 //BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init]; // reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate; // BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; //if(flag) //{ // NSLog(@"反geo检索发送成功"); //[_locService stopUserLocationService]; // } // else //{ // NSLog(@"反geo检索发送失败"); // } //} /** *在地图View停止定位后,会调用此函数 *@param mapView 地图View */ - (void)didStopLocatingUser { NSLog(@"stop locate"); } /** *定位失败后,会调用此函数 *@param mapView 地图View *@param error 错误号,参考CLError.h中定义的错误号 */ - (void)didFailToLocateUserWithError:(NSError *)error { NSLog(@"location error"); } /** *用户位置更新后,会调用此函数 *@param userLocation 新的用户位置 */ - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation { NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude); // latitude = userLocation.location.coordinate.latitude; // longitude = userLocation.location.coordinate.longitude; locateLatitude = userLocation.location.coordinate.latitude; locateLongitude = userLocation.location.coordinate.longitude; [_mapView updateLocationData:userLocation]; _mapView.centerCoordinate = userLocation.location.coordinate; //更新当前位置到地图中间 //地理反编码 BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init]; reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate; BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; if(flag) { NSLog(@"反geo检索发送成功"); //[latitudeLabel setText:[NSString stringWithFormat:@"经度:%lf",longitude]]; // [longitudeLabel setText:[NSString stringWithFormat:@"纬度:%lf",latitude]]; [_mapView removeAnnotations:_mapView.annotations]; //[self addPointAnnotation]; //[_locService stopUserLocationService]; } else { NSLog(@"反geo检索发送失败"); } } #pragma mark 底图手势操作 /** *点中底图标注后会回调此接口 *@param mapview 地图View *@param mapPoi 标注点信息 */ - (void)mapView:(BMKMapView *)mapView onClickedMapPoi:(BMKMapPoi*)mapPoi { NSLog(@"onClickedMapPoi-%@",mapPoi.text); NSString* showmeg = [NSString stringWithFormat:@"您点击了底图标注:%@,\r\n当前经度:%f,当前纬度:%f,\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d", mapPoi.text,mapPoi.pt.longitude,mapPoi.pt.latitude, (int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking]; //latitude = mapPoi.pt.latitude; //longitude = mapPoi.pt.longitude; _mapView.centerCoordinate = mapPoi.pt; //更新当前位置到地图中间 //地理反编码 BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init]; reverseGeocodeSearchOption.reverseGeoPoint = mapPoi.pt; BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; if(flag) { NSLog(@"反geo检索发送成功"); //[latitudeLabel setText:[NSString stringWithFormat:@"经度:%lf",longitude]]; //[longitudeLabel setText:[NSString stringWithFormat:@"纬度:%lf",latitude]]; [_mapView removeOverlays:_mapView.overlays]; [_mapView removeAnnotations:_mapView.annotations]; //[self addPointAnnotation]; //[_locService stopUserLocationService]; } else { NSLog(@"反geo检索发送失败"); } NSLog(showmeg); } /** *点中底图空白处会回调此接口 *@param mapview 地图View *@param coordinate 空白处坐标点的经纬度 */ - (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate { NSLog(@"onClickedMapBlank-latitude==%f,longitude==%f",coordinate.latitude,coordinate.longitude); NSString* showmeg = [NSString stringWithFormat:@"您点击了地图空白处(blank click).\r\n当前经度:%f,当前纬度:%f,\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d", coordinate.longitude,coordinate.latitude, (int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking]; //latitude = coordinate.latitude; //longitude = coordinate.longitude; _mapView.centerCoordinate = coordinate; //更新当前位置到地图中间 //地理反编码 BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init]; reverseGeocodeSearchOption.reverseGeoPoint = coordinate; BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; if(flag) { NSLog(@"反geo检索发送成功"); //[latitudeLabel setText:[NSString stringWithFormat:@"经度:%lf",longitude]]; //[longitudeLabel setText:[NSString stringWithFormat:@"纬度:%lf",latitude]]; [_mapView removeAnnotations:_mapView.annotations]; //[self addPointAnnotation]; //[_locService stopUserLocationService]; } else { NSLog(@"反geo检索发送失败"); } NSLog(showmeg); } /** *双击地图时会回调此接口 *@param mapview 地图View *@param coordinate 返回双击处坐标点的经纬度 */ - (void)mapview:(BMKMapView *)mapView onDoubleClick:(CLLocationCoordinate2D)coordinate { NSLog(@"onDoubleClick-latitude==%f,longitude==%f",coordinate.latitude,coordinate.longitude); NSString* showmeg = [NSString stringWithFormat:@"您双击了地图(double click).\r\n当前经度:%f,当前纬度:%f,\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d", coordinate.longitude,coordinate.latitude, (int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking]; // latitude = coordinate.latitude; // longitude = coordinate.longitude; // // [_mapView removeOverlays:_mapView.overlays]; // [_mapView removeAnnotations:_mapView.annotations]; // [self addPointAnnotation]; // [self addAnimatedAnnotation]; NSLog(showmeg); } /** *长按地图时会回调此接口 *@param mapview 地图View *@param coordinate 返回长按事件坐标点的经纬度 */ - (void)mapview:(BMKMapView *)mapView onLongClick:(CLLocationCoordinate2D)coordinate { NSLog(@"onLongClick-latitude==%f,longitude==%f",coordinate.latitude,coordinate.longitude); NSString* showmeg = [NSString stringWithFormat:@"您长按了地图(long pressed).\r\n当前经度:%f,当前纬度:%f,\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d", coordinate.longitude,coordinate.latitude, (int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking]; // latitude = coordinate.latitude; // longitude = coordinate.longitude; // [_mapView removeOverlays:_mapView.overlays]; // [_mapView removeAnnotations:_mapView.annotations]; // [self addPointAnnotation]; // [self addAnimatedAnnotation]; NSLog(showmeg); } - (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { NSString* showmeg = [NSString stringWithFormat:@"地图区域发生了变化(x=%d,y=%d,\r\nwidth=%d,height=%d).\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d",(int)_mapView.visibleMapRect.origin.x,(int)_mapView.visibleMapRect.origin.y,(int)_mapView.visibleMapRect.size.width,(int)_mapView.visibleMapRect.size.height,(int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking]; // latitude = coordinate.latitude; // longitude = coordinate.longitude; NSLog(showmeg); } #pragma mark implement BMKMapViewDelegate // 根据anntation生成对应的View - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id )annotation { //普通annotation if ( annotation == pointAnnotation) { NSString *AnnotationViewID = @"renameMark"; BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; if (annotationView == nil) { annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; // 设置颜色 annotationView.pinColor = BMKPinAnnotationColorPurple; // 从天上掉下效果 annotationView.animatesDrop = NO; // 设置可拖拽 annotationView.draggable = YES; annotationView.image = [UIImage imageNamed:@"addressAnnota"]; } return annotationView; } //动画annotation NSString *AnnotationViewID = @"AnimatedAnnotation"; MyAnimatedAnnotationView *annotationView = nil; if (annotationView == nil) { annotationView = [[MyAnimatedAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; } NSMutableArray *images = [NSMutableArray array]; for (int i = 1; i < 4; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"poi_%d.png", i]]; [images addObject:image]; } annotationView.annotationImages = images; return annotationView; } // 当点击annotation view弹出的泡泡时,调用此接口 - (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view; { CLLocationCoordinate2D coordinate; coordinate.latitude = locateLatitude; coordinate.longitude = locateLongitude; _mapView.centerCoordinate = coordinate; //更新当前位置到地图中间 //地理反编码 BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init]; reverseGeocodeSearchOption.reverseGeoPoint = coordinate; BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; if(flag) { NSLog(@"反geo检索发送成功"); //[latitudeLabel setText:[NSString stringWithFormat:@"经度:%lf",locateLongitude]]; // [longitudeLabel setText:[NSString stringWithFormat:@"纬度:%lf",locateLatitude]]; [_mapView removeAnnotations:_mapView.annotations]; //[self addPointAnnotation]; //[_locService stopUserLocationService]; } else { NSLog(@"反geo检索发送失败"); } NSLog(@"paopaoclick"); } - (void)dealloc { if (_mapView) { _mapView = nil; } } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end