سؤال

أحاول إعادة تعزيز اسم المدينة مع Cllocation و MkreversegeOcoder. في طريقة ViewDidload الخاصة بي ، Istance CllocationManager:

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 =@ "Unknow";

يعمل التطبيق فقط في المرة الأولى التي أحصل فيها على قيمتي. في المرة الثانية تحطم التطبيق. أعتقد أنه بسبب بدء الجيوكودير وأعتقد أنه يجب أن يكون لدي واحد واحد فقط يعمل. (لكنني لست حقًا هذا ...). في أي طريقة يمكنني التحكم في الجيوكيوم؟

لقد رأيت أنه يمكنني istance mkreversegeOcoder في Lea ViewDidload باستخدام cllocationCoordinate2d ولكن ... في أي طريقة يمكنني إعادة توحيد newLocation.coordinate؟

لقد حلت جزئيًا إعلان الجغرافي المتغير والتحقق

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

لكن .... إذا في بلدي

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

أو في بلدي

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

أطلق سراح أو إلغاء كائني؟ أشعر بالغباء للغاية: د

هل كانت مفيدة؟

المحلول

لا تنشئ الجغرافي العكسي كمتغير محلي.

انظر إلى مثال mkreversegoder في العنوان الحالي نموذج التطبيق المقدمة من Apple. انظر MapViewController.h و MapViewController.M.

اتبع نفس النمط في الكود الخاص بك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top