获取当前位置信息-ios
locationManager= [[CLLocationManager alloc] init];//位置管理器 locationManager.desiredAccuracy = kCLLocationAccuracyBest;//精度,设可而止 locationManager.delegate = self;//设置委托 locationManager.distanceFilter = 100.0f;//距离删选器 [locationManager startUpdatingLocation]; //启动位置管理器 #pragma mark - #pragma mark locationManager - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //获取所在地城市名 CLGeocoder *geocoder=[[CLGeocoder alloc]init]; [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks,NSError *error) { for(CLPlacemark *placemark in placemarks) { NSString *str1=[[placemark.addressDictionary objectForKey:@"Name"] substringFromIndex:0]; NSLog(@"%@", [NSString stringWithFormat:@"我的位置:%@",str1]); UITextView *locText = (UITextView*)[self.view viewWithTag:]; } }]; //map region [geocoder release]; } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { if (error.code == kCLErrorDenied) { [[[[UIAlertView alloc] initWithTitle:@"错误信息" message:@"无法获取您的定位信息" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show]; [locationManager stopUpdatingLocation]; } }