2

So I've been looking at this for a while, and I can't seem to find a solution anywhere. I am trying to use CLGeocoder in an iOS app to find the nearest city to where the user long taps on the map. I have two main problems:

  1. Even if the user is very zoomed out, and the user taps on say New York (which is what they intend), because of how zoomed out the map is, CLGeocoder often returns a nearby city instead of the more obvious answer of New York. I can't work out how to set the "fuzziness" of the search to overcome this issue.
  2. In many instances the City field is null in the returned placemark object, most commonly in remote areas such as deserts or oceans. In this case, I would ideally want to find the nearest object that actually has City defined, but can't work out how to do this.
4

1 回答 1

0

通过使用获取您的位置的所有详细信息CLGeocoder

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

    CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:latitudeValue longitude:longitudeValue];


    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];

    [geoCoder reverseGeocodeLocation:myLocation completionHandler:^(NSArray *placemarks, NSError *error) {

        if(!error)
        {
            for (CLPlacemark * placemark in placemarks)
            {
                NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
                NSLog(@"placemark.country %@",placemark.country);
                NSLog(@"placemark.postalCode %@",placemark.postalCode);
                NSLog(@"placemark.administrativeArea %@",placemark.administrativeArea);
                NSLog(@"placemark.locality %@",placemark.locality);
                NSLog(@"placemark.subLocality %@",placemark.subLocality);
                NSLog(@"placemark.subThoroughfare %@",placemark.subThoroughfare);

            }

        }
        else
        {
            NSLog(@"failed getting city: %@", [error description]);
        }

    }];


}
于 2013-02-12T14:11:05.980 回答