先说下这功能的流程, 流程:判断用户是否联网--->获取用户地理位置经纬度--->通过经纬度去查询地理位置名称
//高德地图@property (nonatomic, strong) MAMapView *mapView;//高德地图@property (nonatomic, strong) AMapSearchAPI *search;@property(nonatomic,strong)NSString *longitude;@property(nonatomic,strong)NSString *latitude;@property (nonatomic, strong) CLLocationManager *locationManager;//本地信息存储类@property(nonatomic,strong) AMapAddressComponent *compantAddress;@property(nonatomic,strong) NSMutableArray *CellContentArray;@property(nonatomic,strong)NSString *currentCityName;@property(nonatomic,strong)NSString *tempRecordIsOrNoSelect;//是否是首次加载定位@end@implementation HomeController//通知设置值 根据选中的地区加载相应的数据- (void)setCurrentLocation:(NSNotification *)text{//移除通知[[NSNotificationCenter defaultCenter] removeObserver:self name:@"citySelectLocationReciveceMethod" object:nil];_currentCityName= [NSString stringWithFormat:@"%@",text.object];if (_currentCityName.length>3) {_currentCityName=[_currentCityName substringToIndex:3];}else{}_tempRecordIsOrNoSelect=_currentCityName;}-(void)viewWillAppear:(BOOL)animated{[super viewWillAppear:YES];[[AFNetworkReachabilityManager sharedManager] startMonitoring];//开启网络监听if (self.navigationController.navigationBar.hidden) {self.navigationController.navigationBarHidden=NO;}[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setCurrentLocation:) name:@"citySelectLocationReciveceMethod" object:nil];//地图定位[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {// if (_tempRecordIsOrNoSelect.length==0) {if(status==AFNetworkReachabilityStatusNotReachable){showMessage(@"请检查网络是否畅通!");_tempRecordIsOrNoSelect=nil;[SVProgressHUD dismiss];return ;}else{
if (_tempRecordIsOrNoSelect.length==0) {[SVProgressHUD showWithStatus:@"定位中......" maskType:SVProgressHUDMaskTypeBlack];_longitude=[[NSString alloc]init];_latitude=[[NSString alloc]init];self.mapView=[[MAMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];self.mapView.userTrackingMode = 1,_mapView.showsUserLocation = YES;self.mapView.userTrackingMode = MAUserTrackingModeNone;self.mapView.delegate=self;}else{CGRect tempLeftButtonFrame=self.LeftButton.frame;_tempRecordIsOrNoSelect=_currentCityName;[self setLeftButtonTitle:_currentCityName setFontColor:[UIColor whiteColor] setFontSize:16 setFrme:&tempLeftButtonFrame];}}}];self.title=@"首页";//高德地图 }//高德地图代理- (void)mapViewWillStartLocatingUser:(MAMapView *)mapView{if(![CLLocationManager locationServicesEnabled]){UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"定位失败" message:@"请在手机设置中开启定位功能\n开启步骤:设置 > 隐私 > 位置 > 定位服务" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];[alertView show];self.mapView = nil;self.mapView.delegate = nil;return;}else{if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"定位失败" message:@"请在手机设置中开启定位功能\n开启步骤:设置 > 隐私 > 位置 > 定位服务下《***》应用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];[alertView show];self.mapView = nil;self.mapView.delegate = nil;return;}}}- (void)mapViewDidStopLocatingUser:(MAMapView *)mapView{_longitude=[NSString stringWithFormat:@"%f",mapView.userLocation.location.coordinate.longitude];//@"106.546128";// _latitude= [NSString stringWithFormat:@"%f",mapView.userLocation.location.coordinate.latitude];//@"29.559153";_search = [[AMapSearchAPI alloc] initWithSearchKey:@"e4bb6f15bba9fde10b1cfc13b298370e" Delegate:self];AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequest alloc] init];regeoRequest.searchType = AMapSearchType_ReGeocode;regeoRequest.location =[AMapGeoPoint locationWithLatitude:[_latitude floatValue] longitude:[_longitude floatValue]];regeoRequest.radius = 10000;regeoRequest.requireExtension = YES;//发起逆地理编码 [_search AMapReGoecodeSearch: regeoRequest];}//逆编码查询代理- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{if(response.regeocode != nil){_compantAddress=response.regeocode.addressComponent;_currentCityName=_compantAddress.province;if (_currentCityName.length>3) {_currentCityName=[_currentCityName substringToIndex:3];}_tempRecordIsOrNoSelect=_currentCityName;//定位后也要给这个临时判断是否选择的变量赋值[self setLeftButtonTitle:_currentCityName setFontColor:[UIColor whiteColor] setFontSize:16 setFrme:&computeFrame];UIImageView *pointView=[[UIImageView alloc]initWithFrame:CGRectMake(computeFrame.size.width-2,10, 13, 8 )];[pointView setImage:[UIImage imageNamed:@"fanhuijiantou.png"]];[pointView setBackgroundColor:[UIColor clearColor]];[self.LeftButton addSubview:pointView];[self.LeftButton addTarget:self action:@selector(changeLocationClick:) forControlEvents:UIControlEventTouchUpInside];self.LeftButton.hidden=NO;}else{showMessage(@"请检查网是否畅通!");}[SVProgressHUD dismiss];}- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation{mapView.showsUserLocation = NO;}
本人做的一款androidApp,积分墙下载可兑支付宝红包,无广告看最新国内外大片,各种当前热门H5页游,淘宝天猫高额购物券!!:扫描下载,多谢支持!若有需要做此类产品的可以联系我:2819936788,各类数据API接口!(手机/流量/QB/游戏/淘宝客高额优惠券/超便宜的代理IP API/产品推广工具API)