11

私はここで別の質問から見ました: iPhoneのユーザーがいる現在の国を取得することが可能であるiPhoneユーザーの国を決定します。

そして、それは多くの用途に非常に便利です。しかし、iOSからさらに深く掘り下げて(情報がある場合)、ユーザーがどの州または都市にいるかを推測することは可能でしょうか?

それが不可能な場合は、逆ジオコーディングサービスが次のステップになると思います。アプリに逆ジオコーディングサービスを雇うこともできますか?

4

4 に答える 4

26

MKReverseGeocoderは iOS 5 で非推奨になりました。CLGeocoder

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
   [self.locationManager stopUpdatingLocation];

   CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
   [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
       for (CLPlacemark * placemark in placemarks) {
           .... = [placemark locality];
        }    
    }];
}
于 2012-03-26T15:54:19.287 に答える
24
CLGeocoder *geocoder = [[CLGeocoder alloc] init];

CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:21.1700
                                                    longitude:72.8300];

[geocoder reverseGeocodeLocation:newLocation
               completionHandler:^(NSArray *placemarks, NSError *error) {

                   if (error) {
                       NSLog(@"Geocode failed with error: %@", error);
                       return;
                   }

                   if (placemarks && placemarks.count > 0)
                   {
                       CLPlacemark *placemark = placemarks[0];

                       NSDictionary *addressDictionary =
                       placemark.addressDictionary;

                       NSLog(@"%@ ", addressDictionary);
                       NSString *address = [addressDictionary
                                            objectForKey:(NSString *)kABPersonAddressStreetKey];
                       NSString *city = [addressDictionary
                                         objectForKey:(NSString *)kABPersonAddressCityKey];
                       NSString *state = [addressDictionary
                                          objectForKey:(NSString *)kABPersonAddressStateKey];
                       NSString *zip = [addressDictionary 
                                        objectForKey:(NSString *)kABPersonAddressZIPKey];


                       NSLog(@"%@ %@ %@ %@", address,city, state, zip);
                   }

               }];

結果

{

  City = Surat;
  Country = India;
  CountryCode = IN;
  FormattedAddressLines =     (
    Surat,
    Gujarat,
    India
);
Name = Surat;
State = Gujarat;
} 
2012-12-20 21:33:26.284 CurAddress[4110:11603] (null) Surat Gujarat (null)
于 2012-12-20T16:07:08.600 に答える
5

私はCLReverseGeocoderクラスから始めます。

このstackoverflowの質問は現在の都市を取得し、おそらくあなたの使用に適合させることができます。

于 2011-02-20T17:50:48.050 に答える
3

次のコードは、完全な詳細を簡単に取得できます。

 [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if(placemarks.count){

        placeNameLabel.text = [placemarks[0] name];
        streetNumberLabel.text = [placemarks[0] subThoroughfare];
        streetLabel.text = [placemarks[0] thoroughfare];
        neighborhoodLabel.text = [placemarks[0] subLocality];
        cityLabel.text = [placemarks[0] locality];
        countyLabel.text = [placemarks[0] subAdministrativeArea];
        stateLabel.text = [placemarks[0] administrativeArea];    //or province 
        zipCodeLabel.text = [placemarks[0] postalCode];
        countryLabel.text = [placemarks[0] country];
        countryCodeLabel.text = [placemarks[0] ISOcountryCode];
        inlandWaterLabel.text = [placemarks[0] inlandWater];
        oceanLabel.text = [placemarks[0] ocean];
        areasOfInterestLabel.text = [placemarks[0] areasOfInterest[0]];
        }
    }];
于 2013-09-03T00:48:37.177 に答える