MKReverseGeocoder不会调用代理

时间:2010-12-17 20:26:33

标签: iphone cocoa-touch

我正在尝试获取MKMapView的用户位置的地址。

这是我的代码:

CLLocationCoordinate2D userCoordinate = mapview.userLocation.location.coordinate;


MKReverseGeocoder *geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:userCoordinate] autorelease];

geocoder.delegate = self;
[geocoder start];

locationInstructions.text = @"Finding your location...";

NSLog(@"Started Geocoder");

日志被称为正常,如果我记录NSLog(%p,geocorder.delegate);,则不会返回nil。所以我的代表没有错。

现在转到委托方法:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error;
{
    NSLog(@"Failed!");
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
    NSString*str = [NSString stringWithFormat:@"%@,%@,%@,%@",[placemark thoroughfare],[placemark locality],[placemark administrativeArea],[placemark country]];

    NSLog(@"%@",str);
}

没有一个代表被召唤过。为什么是这样?我错过了什么?

3 个答案:

答案 0 :(得分:0)

您是否在标题中实施了MKReverseGeocoderDelegate

答案 1 :(得分:0)

可能首先需要自动重新发布地理编码器。

按abitobvious编辑:将地理编码器分配给实例变量/属性,然后在释放包含对象时显式释放该实例变量/属性。

答案 2 :(得分:0)

您应该在实例级别定义MKReverseGeocoder *geoCoder,而不是在方法级别定义。

我遇到了同样的问题,它也适用于我:)

罗希特夏尔