Ios 首先检查用户坐标,然后启用功能
在我的项目中,我需要检查用户坐标。如果用户居住在美国,那么我将启用一个显示空气质量的功能。然后进一步,如果用户住在休斯顿和周围地区,那么我将启用另一个功能,显示另一个功能,臭氧值。我怎样才能做到这一点?我可以用下面的代码检测休斯顿及其周边地区,但我不知道如何将美国各州与休斯顿和世界区分开来Ios 首先检查用户坐标,然后启用功能,ios,mapkit,coordinates,Ios,Mapkit,Coordinates,在我的项目中,我需要检查用户坐标。如果用户居住在美国,那么我将启用一个显示空气质量的功能。然后进一步,如果用户住在休斯顿和周围地区,那么我将启用另一个功能,显示另一个功能,臭氧值。我怎样才能做到这一点?我可以用下面的代码检测休斯顿及其周边地区,但我不知道如何将美国各州与休斯顿和世界区分开来 if((currentLocation.latitude>=28.930661 && currentLocation.latitude<=30.443953 &&
if((currentLocation.latitude>=28.930661 && currentLocation.latitude<=30.443953 && currentLocation.longitude>=-95.899668 && currentLocation.longitude<=-94.690486) ||
currentLocation.longitude == 0 || currentLocation.latitude == 0) {
// It is in the bounds
[self.opponentAvatarImageView removeFromSuperview];
UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:@"Would you like to see ozone cloud in your area or a trace of your walking/driving/biking activity" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"OzoneMap", @"TraceMap", nil];
[actionsheet showInView:self.view];
}
if((currentLocation.latitude>=28.930661&¤tLocation.latitude=-95.899668&¤tLocation.longitude使用CLGeocoder类传入您的位置(CLLocation),并让它为您反向地理编码地址。您甚至可以获得城市的具体信息
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:
^(NSArray* placemarks, NSError* error){
CLPlacemark *placemark = [placemarks firstObject];
if ([placemark.country isEqualToString:@"United States"]) {
// You're in the U.S.
}
}];