我正在尝试获取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);
}
没有一个代表被召唤过。为什么是这样?我错过了什么?
答案 0 :(得分:0)
您是否在标题中实施了MKReverseGeocoderDelegate
?
答案 1 :(得分:0)
可能首先需要不自动重新发布地理编码器。
按abitobvious编辑:将地理编码器分配给实例变量/属性,然后在释放包含对象时显式释放该实例变量/属性。
答案 2 :(得分:0)
您应该在实例级别定义MKReverseGeocoder *geoCoder
,而不是在方法级别定义。
我遇到了同样的问题,它也适用于我:)
罗希特夏尔