2010-04-14 3 views
3

나는 cllocation 및 mkreversegeocoder를 사용하여 도시 이름을 검색하려고합니다.cllocation 및 mkreversegeocoder

self.locManager = [[CLLocationManager alloc] init]; 
locManager.delegate = self; 
locManager.desiredAccuracy = kCLLocationAccuracyBest; 
[locManager startUpdatingLocation]; 

이후 :

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation 
*)newLocation 
fromLocation:(CLLocation *)oldLocation { 
//some code to retrieve my information 

MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc]  
initWithCoordinate:newLocation.coordinate ]; 
geoCoder.delegate = self; 
[geoCoder start]; 
} 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark 
*)placemark 
{ 
MKPlacemark *myPlacemark = placemark; 
citta.text = [placemark locality]; 
} 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ 
citta.text [email protected] "Unknow"; 

어플은 내 가치를 얻을 처음에만 작동 제의 viewDidLoad 방법에 은 내가 cllocationmanager을 istance. 두 번째로 앱이 다운됩니다. 지오 코더가 시작 되었기 때문에 내가 생각하기에 단지 하나의 istance가 실행되어야한다고 생각합니다. (그러나 나는 정말로 이것의 shure가 아니다. ..). 어떤 방법으로 나는 지오 코더를 제어 할 수 있습니까?

나는 내 viewdidload에서 cllocationcoordinate2d를 사용하여 istance mkreversegeocoder를 볼 수 있었지만 ... 어떤면에서 newlocation.coordinate를 검색 할 수 있습니까?

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark 
*)placemark 

또는

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError 
*)error 

내가 풀어 내에서 경우

나는 부분적으로 .... 클래스 변수로 지오 코더를 선언하고

if (self.geocoder != nil) { 
    [geocoder release]; 
} 

을 확인하지만 해결했습니다 또는 내 물건을 취소 하시겠습니까? 나는 너무 어리 석다. D

+0

'[nil release]; '는 작동하지 않으므로 확인할 필요가 없습니다. –

답변

7

역방향 지오 코더를 로컬 변수로 만들지 마십시오.

Apple에서 제공 한 CurrentAddress 샘플 응용 프로그램의 MKReverseGeocoder 예제를 살펴보십시오. MapViewController.h 및 MapViewController.m을 참조하십시오.

코드에서 동일한 패턴을 따르십시오.

+0

shure이 방법으로 끝냈습니다. 이제 지오 코더가 실행 중인지 확인하지 않고 autorelease로 수정했습니다. – zebra