【问题标题】:reverse geocode function not executing?反向地理编码功能未执行?
【发布时间】:2012-05-14 17:08:50
【问题描述】:

我正在尝试使用反向地理编码,但该功能没有执行,也不确定为什么..

在这里我附上了我的代码。谢谢你的帮助

//-- reverse geocode, converting from point to address 
- (BNRMapPoint *)geocodeLocation:(CLLocation *)location title:(NSString *)title

{
    if(!geocoder)
    {
        geocoder = [[CLGeocoder alloc] init];
    }

    __block BNRMapPoint * annotation;

    [self.geocoder reverseGeocodeLocation:location completionHandler: 
     ^(NSArray * placeMarks, NSError * errors)
     {
         NSLog(@"in block code");
         if([placeMarks count] > 0)
         {
             NSLog(@"%@", [placeMarks objectAtIndex:0]);
             annotation = [[BNRMapPoint alloc] initWithCoordinate:location.coordinate title:title
                                                    placeMark:[placeMarks objectAtIndex:0]];
             NSLog(@"%@", annotation.placeMark.name);
         }
         else
         {
             NSLog(@"failed!!");
         }

     }];

    return annotation;
}

它没有在控制台打印任何东西..所以我认为它没有输入块代码。 但我真的很困惑为什么它没有进入。再次感谢您的帮助

【问题讨论】:

  • 这是一个远景,但这可能与 LLDB NSLog 错误有关。尝试在viewDidLoad method 中输出一些内容。如果你没有得到输出,看看这个。 NSLog no output in LLDB. Works in GDB
  • 它在 viewDidLoad 中打印得很好......

标签: ios ios5 geocoding reverse-geocoding


【解决方案1】:

我似乎记得在传递给reverseGeocodeLocation 的块中遇到了NSLog 的问题。地理编码器在单独的线程上执行,我期望的块也是如此。 (如果我错了,我相信有人会纠正我)。就我而言,我认为 `UIAlertView 即使在块代码中也能正常工作,所以你可以试试...

我针对与reverseGeocodeLocation 配合使用的应用检查了您的代码,但我认为您的代码没有问题。唯一的区别是我在执行 reverseGeocode 之前检查了if (![geocoder isGeocoding])...。这只是为了防止 geoCoder 调用堆积,这在您的应用中可能无法实现,具体取决于您的代码被调用的方式。

【讨论】:

  • 我检查了属性,地理编码,它返回了 true。我在 (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 中调用我的地理编码函数
【解决方案2】:

可能 self.geocoder = nil?

替换

if(!geocoder)
{
    geocoder = [[CLGeocoder alloc] init];
}

与

if(!self.geocoder)
{
    self.geocoder = [[CLGeocoder alloc] init];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-31
    • 2020-02-26
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多