我正在嘗試獲取用戶位置MKMapView
的地址。MKReverseGeocoder不會調用代理
這裏是我的代碼:
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);
}
代表曾經得到所謂的無。爲什麼是這樣?我錯過了什麼?
不會拋出一個異常,並在應用程序預先發布時崩潰嗎? – Pripyat 2010-12-17 20:39:24
刪除'autorelease'確實有效。我不知道這是爲什麼發生,但它的工作! :) – Pripyat 2010-12-17 20:40:43
儘管刪除autorelease「工作」,你現在有內存泄漏。請按照Apple示例應用中的模式[CurrentAddress](http://developer.apple.com/library/ios/#samplecode/CurrentAddress/Introduction/Intro.html)進行操作。 – Anna 2010-12-17 20:49:51