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

Ios CLGeocoder从给定位置反向地理编码,ios,maps,clgeocoder,Ios,Maps,Clgeocoder,给定的经度和纬度不是我的当前位置如何使用GLGeocoder执行反向地理代码查找 self.geoCoder = [[CLGeocoder alloc] init]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // [self.locationManager startUpdatingLocation]; [self.geoCoder rev

给定的经度和纬度不是我的当前位置如何使用
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];
 }];

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

我从未尝试过这一点,但您不能创建自己的CLLocation对象吗

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

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

如果使用模拟器,您可以调试>位置>自定义位置,然后输入lat long以模拟任何位置。

!非常感谢。我确实尝试了
initWithLatitude
,但它一定是在
CLLocationManager
上,而不是在
CLLocation
对象上。干杯太好了,你救了我。我还用它从PFGeoPoint中反转了地理代码,真是太棒了!