CLGeocoder从给定位置反向地理编码

Jam*_*mes 4 maps ios clgeocoder

鉴于经度和纬度不是我当前的位置,我如何使用GLGeocoder?执行反向地理编码查找?

self.geoCoder = [[CLGeocoder alloc] init];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
//    [self.locationManager startUpdatingLocation];

[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: ^(NSArray *placemarks, NSError *error) {
//        [self.locationManager stopUpdatingLocation];

     CLPlacemark *placemark = [placemarks objectAtIndex:0];
    // Long address
    // NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
    // Short address
    NSString *locatedAt = [placemark subLocality];

     cell.textLabel.text = spot.name;
     cell.detailTextLabel.text = [NSString stringWithFormat:@"Cab no: %@, spotted at %@", spot.cabno, locatedAt];
 }];
Run Code Online (Sandbox Code Playgroud)

显然只会对我的位置进行地理编码,但我需要明确设置经度和纬度来反转.

yee*_*nny 7

我从来没有试过这个,但你不能创建自己的CLLocation对象吗?

如果您知道当前的经度和纬度,您可以 -

CLLocation *location = [[CLLocation alloc]initWithLatitude:someValue longitude:someValue];
[self.geoCoder reverseGeocodeLocation: location completionHandler: ^(NSArray *placemarks, NSError *error) {
    //do something
});
Run Code Online (Sandbox Code Playgroud)