我正在尝试获取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);
}所有的代表都不会被召唤。为什么会这样呢?我遗漏了什么?
发布于 2010-12-18 04:37:47
可能一开始就不需要自动释放地理编码器。
Edit per :将地理编码器分配给一个实例变量/属性,然后在取消分配包含对象时显式释放该变量/属性。
发布于 2010-12-18 04:35:12
你是否在你的头中实现了MKReverseGeocoderDelegate?
发布于 2012-08-25 10:33:06
您应该在实例级别定义MKReverseGeocoder *geoCoder,而不是在方法级别定义。
我也遇到了同样的问题,它也适用于我:)
rohit
https://stackoverflow.com/questions/4474497
复制相似问题