Iphone MKReverseGeocoder不';不要召集代表
我正在尝试获取Iphone MKReverseGeocoder不';不要召集代表,iphone,cocoa-touch,Iphone,Cocoa Touch,我正在尝试获取MKMapView的用户位置的地址 这是我的密码: CLLocationCoordinate2D userCoordinate = mapview.userLocation.location.coordinate; MKReverseGeocoder *geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:userCoordinate] autorelease]; geocoder.delegate = self;
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,geocarder.delegate),则会调用fine日志
,它不会返回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);
}
没有一个代表会接到电话。为什么会这样?我遗漏了什么?您是否在标头中实现了
mkreversegeocoderedelegate
?可能首先不需要自动释放地理编码器
根据abitobevious编辑:将地理编码器分配给实例变量/属性,然后在释放包含对象时显式释放该实例变量/属性。您应该在实例级别定义
MKReverseGeocoder*geocoder
,而不是在方法级别定义
我也有同样的问题,这对我也很有效:)
rohit如果它预先发布了应用程序,它不会引发异常并导致应用程序崩溃吗?删除
自动释放
就成功了。我不知道为什么会发生这种情况,但它起了作用!:)虽然删除自动释放“起作用”,但您现在有内存泄漏。取而代之的是,遵循苹果示例应用程序中的模式。也许可以在标题中定义地理编码器,而不是范围?我在我的一个应用程序中使用了相同的方法,标题中的定义适用于我,使用@property、@synthesis。