都市&の状態情報をMKAnnotationに追加しようとしていますが、データをクリアしてからアノテーションに追加できません。ここで私の現在のコードは、(だけ簡単にするために関心のセクション/部品を示す)である:実装でCLGeocoderを使用してMKAnnotationに市区町村の情報を追加する
:界面における
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
[self setCity:[placemark locality] andState:[placemark administrativeArea]];
}];
NSLog(@"Location 1: %@, %@", city, state);
MapPoint *mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate]
title:[locationTitleField text]
date:[dateFormat stringFromDate:today]];
[mapView addAnnotation:mp];
}
- (void)setCity:(NSString *)c andState:(NSString *)s
{
[self setCity:c];
[city retain];
[self setState:s];
[state retain];
NSLog(@"Location 2: %@, %@", city, state);
}
:
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate, MKMapViewDelegate>
{
CLLocationManager *locationManager;
IBOutlet MKMapView *mapView;
NSString *city;
NSString *state;
}
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (nonatomic, copy) NSString *city;
@property (nonatomic, copy) NSString *state;
- (void)setCity:(NSString *)c andState:(NSString *)s;
@end
ロケーション1つの印刷(NULL)、( null)、Location 2はカリフォルニア州サンフランシスコを印刷します。注釈で使用する前に、これらのプロパティからデータが消去されるのはなぜですか?
ありがとう...
ここで、MKAnnotationを設定しますか? –
MKAnnotationの設定位置を示すコードをいくつか追加しました。クラスMapPointは、MKAnnotationプロトコルに準拠しています。日付のことについて心配しないでください。注釈を付ける前に街と州を得ることができれば、それを副題に追加します。 –
それは問題を説明します。私の答えの更新されたセクションを参照してください。 –