2011-08-15 5 views
0

ビューを読み込むときにユーザーの現在の場所に注釈を追加しようとしています。それについてどうすればいいですか?私が新しいもののように事例があるといいですね。viewDidAppearでユーザーの場所を表示

ありがとうございます。

答えて

1

私は次のようでした注釈として現在位置を表示すると:

// Set up the annotation 
LocationAnnotation *annotation = [[LocationAnnotation alloc] initWithLatitude:[numberFormatter numberFromString:[[location valueForKey:@"latitude"] description]] andLongitude:[numberFormatter numberFromString:[[location valueForKey:@"longitude"] description]] andTitle:[location valueForKey:@"name"] andSubtitle:[location valueForKey:@"notes"]]; 
[numberFormatter release]; 

[self.mapView addAnnotation:annotation]; 

注釈ヘッダクラスは次のようになります。

@interface LocationAnnotation : NSObject <MKAnnotation> { 

UIImage *image; 
NSNumber *latitude; 
NSNumber *longitude; 
NSString *locationTitle; 
NSString *locationSubtitle; 
} 

@property (nonatomic, retain) UIImage *image; 
@property (nonatomic, retain) NSNumber *latitude; 
@property (nonatomic, retain) NSNumber *longitude; 

@property(nonatomic,retain) NSString *locationTitle; 
@property(nonatomic,retain) NSString *locationSubtitle; 

-(id)initWithLatitude:(NSNumber *)aLatitude andLongitude:(NSNumber *)aLongitude andTitle:(NSString *)aLocationTitle andSubtitle:(NSString *)aLocationSubtitle; 

@end 

addAnnotation方法とMKAnnotation議定書は何」ですこれを達成するために探しています。

カスタムの場所を表示したい場合は、ここで述べたように、あなたがあなた自身のMKAnnotationを作成する周り来ることはありませんが:

loading custom image on mkmaps

+0

私はこれを知っていますが、それは私が望んでいないことです。私はそれに自分の注釈を追加したい。 – deathman91

+0

viewDidAppearでユーザーの現在の緯度と経度を取得するにはどうすればよいですか? – deathman91

+0

現在の座標は、 'CLLocationManager'の' coordinate'プロパティで取得できます - http://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#を参照してください。 // apple_ref/doc/uid/TP40007126 –

1

あなたMKMapViewYESへのshowsUserLocationプロパティを設定していることを確認します。

このプロパティのみは、がユーザーの場所の表示を有効にします。

関連する問題