0

这是场景。我有两个 UIViewControllers。可以说,PresentinLondonViewControllerNotPresentinLondonViewController。我想首先加载的视图应该取决于当前用户。假设当且仅当当前用户位置是伦敦,那么我希望 PresentViewController 显示,否则 NotPresentViewController。

我做了很多研究,甚至尝试过协议都找不到任何具体的东西。对我不起作用。

4

3 回答 3

1

您可以使用CLLocationManager获取当前位置,然后您可以reverse geocoding从坐标中获取地址。

在那个地址中,如果它是准确的,您会找到London符合您需要的单词“ ”。

这样做- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

CLLocationManager *manager = [[CLLocationManager alloc] init];
manager.delegate = self;
//Here you set the Distance Filter that you need
manager.distanceFilter = kCLDistanceFilterNone;
// Here you set the Accuracy 
  manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[manager startUpdatingLocation];

在委托函数中:

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{


        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
            //Picked the first placemark
             CLPlacemark *placemark = placemarks[0];
           //you can play and see how to grab the key name that you want.
             NSLog(@"Address %@",[NSString stringWithFormat:@"%@ %@",placemark.thoroughfare,addressNumber]);
          //Do your additional setup here

        }];
        [geocoder release];
        [location release];

}

如果您想延迟加载以便有时间获取所有信息,那么您可以出示另一个上面viewcontroller有 的splash screen信息并在那里/或在appDelegate.

于 2013-07-08T07:38:12.603 回答
0

您可以使用 MKReverseGeocoder获取MKPlacemark ,您可以获取CurrentAddress的苹果示例代码

或者这里是另一个链接

目标c如何获取给定坐标的地标

于 2013-07-08T07:41:44.760 回答
0

CLLocationManager从你必须使用的获取当前的 latLong

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
//for iOS 6+
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation 
{
//for lower then iOS 6
}

从您的经纬度和经度获取地址,请使用此网址

    NSString *urlString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=%f,%f",YourLatitude,YourLongitude];
于 2013-07-08T07:44:54.667 回答