在我的项目中,我需要检查用户坐标。如果用户居住在美国,那么我将启用一个显示空气质量的功能。然后,如果用户住在休斯顿及周边地区,那么我将启用另一个功能,显示另一个功能,即臭氧值。我怎么能实现这一目标?我可以用以下代码检测休斯顿及周边地区,但我不知道如何从休斯顿和世界找到美国各州。
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];
}
答案 0 :(得分:3)
使用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.
}
}];