2019独角兽企业重金招聘Python工程师标准>>>
参考
iOS 根据地名获取经纬度
iOS 根据经纬度显示地名
- (void)setCity {[[LoginUserInfo sharedLoginUserInfo] latitude];NSLog(@"%@",[[LoginUserInfo sharedLoginUserInfo] latitude]);NSLog(@"------%@",[[LoginUserInfo sharedLoginUserInfo] longitude]);CLLocationCoordinate2D coordinate;coordinate.latitude = [[NSString stringWithFormat:@"%@",[[LoginUserInfo sharedLoginUserInfo] latitude]] floatValue];coordinate.longitude = [[NSString stringWithFormat:@"%@",[[LoginUserInfo sharedLoginUserInfo] longitude]] floatValue];CLLocation * newLocation = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];NSLog(@"%f",coordinate.latitude);NSLog(@"------%f",coordinate.longitude);CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];[clGeoCoder reverseGeocodeLocation:newLocation completionHandler: ^(NSArray *placemarks,NSError *error) {CLPlacemark*placemark = [placemarks objectAtIndex:0];NSString * LocationAddress = [NSString stringWithFormat:@"%@%@%@%@", placemark.locality, placemark.subLocality,placemark.thoroughfare, placemark.subThoroughfare];NSLog(@"%@",LocationAddress);NSLog(@"%@",placemark.locality);if (placemark.locality) {NSMutableString * str = [[NSMutableString alloc] initWithString:placemark.locality];[self setcity:[str substringToIndex:str.length-1]];}//}];
}
- (void)addressPicker:(BAddressPickerController *)addressPicker didSelectedCity:(NSString *)city{NSLog(@"%@",city);CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];[myGeocoder geocodeAddressString:city completionHandler:^(NSArray *placemarks, NSError *error) {if ([placemarks count] > 0 && error == nil) {NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks count]);CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);//获取经度NSString *longgitudeStr = nil;longgitudeStr = [NSString stringWithFormat:@"%3.5f",firstPlacemark.location.coordinate.longitude];//获取纬度NSString *latitudeStr = nil;latitudeStr = [NSString stringWithFormat:@"%3.5f",firstPlacemark.location.coordinate.latitude];// 保存用户的当前位置//开始定位[[LoginUserInfo sharedLoginUserInfo] setLatitude:latitudeStr]; // 纬度[[LoginUserInfo sharedLoginUserInfo] setLongitude:longgitudeStr]; // 经度}else if ([placemarks count] == 0 && error == nil) {NSLog(@"Found no placemarks.");} else if (error != nil) {NSLog(@"An error occurred = %@", error);}}];[self.delegate setcity:city];[self dismissViewControllerAnimated:YES completion:nil];}
这是两个文件里面的具体使用,大家可以参考