2012-02-02 14 views
1

plistを初めて使用しています。私は周りをブラウジングしていて、私は他の助けを見つけることができません。plistから読み込まれた注釈は表示されません

私のコードはviewDidLoadです。どのように注釈が表示されないのですか?注釈の

mapView.showsUserLocation = YES; 
mapView.delegate=self; 


NSMutableArray *annotations = [[NSMutableArray alloc]init]; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"StationAddress" ofType:@"plist"]; 
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; 
NSArray *anns = [dict objectForKey:@"GasStation"]; 
NSLog(@" MapView is %@",mapView); 
NSLog(@"anns is: %@", anns); 


for(int i = 0; i < [anns count]; i++) { 
    NSLog(@"read2"); 

    double realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] doubleValue]; 
    NSLog(@" double lat value is %f",realLatitude); 
    double realLongitude = [[[anns objectAtIndex:i] objectForKey:@"Longitude"] doubleValue]; 
    NSLog(@" double lot value is %f",realLatitude); 

    NSLog(@"read3"); 



    MyAnnotation *myAnnotation = [[MyAnnotation alloc] init]; 
    CLLocationCoordinate2D theCoordinate; 
    theCoordinate.latitude = realLatitude; 
    theCoordinate.longitude = realLongitude; 
    myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude); 

    myAnnotation.title = [[anns objectAtIndex:i] objectForKey:@"Name"]; 
    myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:@"Address"]; 


    [mapView addAnnotation:myAnnotation]; 
    [annotations addObject:myAnnotation]; 
    [myAnnotation release]; 

EDIT MyAnnotation.h

@interface MyAnnotation : NSObject<MKAnnotation> { 

CLLocationCoordinate2D coordinate; 
NSString*    title; 
NSString*    subtitle; 

}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate; 
@property (nonatomic, copy)  NSString*    title; 
@property (nonatomic, copy)  NSString*    subtitle; 

MyAnnotation.m

@implementation MyAnnotation 

@synthesize title; 
@synthesize subtitle; 
@synthesize coordinate; 

ハードコード(これはのviewDidLoad内にある)

[mapView setShowsUserLocation:YES]; 

CLLocation *userLoc = mapView.userLocation.location; 
CLLocationCoordinate2D userCoordinate = userLoc.coordinate; 


NSLog(@"user latitude = %f",userCoordinate.latitude); 
NSLog(@"user longitude = %f",userCoordinate.longitude); 

mapView.delegate=self; 

NSMutableArray* annotations=[[NSMutableArray alloc] init]; 

MKPointAnnotation *annot1 = [[MKPointAnnotation alloc] init]; 
annot1.title = @"TItle1"; 
[email protected]"Address of title"; 
annot1.coordinate = CLLocationCoordinate2DMake(21.946114, 120.792778); 
[mapView addAnnotation:annot1]; 

と私は彼らの3000のためにこれをやったが、彼らは遅い走ったので、私は

+0

最初のNSLogにはいくつの注釈が表示されますか?緯度と経度の値を記録して、それらが正しいことを確認してください。 'mapView'がnilでないことを確認してください。また、 '[MyAnnotation release];'は[myAnnotation release]; 'でなければなりません。 – Anna

+0

申し訳ありませんあなたが求めていることの一部を理解するにはあまりにも初心者かもしれませんが、これは最初のNSlogから出てくるものです:{ アドレス= "¥U5f70¥U5316¥U7e23¥U798f¥U8208¥U9109¥U6cbf¥U6d77 \ U8def \ U56db \ U6bb5256 \ U865f "; Latitude = "24.035067"; 経度= "120.419800"; 名前= "\ U53f0 \ U5851 \ U77f3 \ U6cb9"; } で、約2000以上のものがあります。私はそれをハードコーディングすると、それは完璧に表示されますが、一度私はこのplistを使用すると、それはディッパーです。 mapViewは無しではないと確信しています。私はMy to myを変更しました。あなたのお役に立てると心よりお待ちしております。ありがとう! –

+0

または、他の人にそれをすることをお勧めしますか?どうもありがとうございます。 @Anna Karenina –

答えて

0

はこれを試してみてくださいより良い方法を見つけようとしています。

変更:これに

 float realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] floatValue]; 

 double realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] doubleValue]; 
    NSLog(@" double lat value is %f",realLatitude); 

(も経度を行います)。

ヒント:Equatorial Guineaの南西にある南大西洋の注釈をチェックしてください。{0,0}のLat/Lonがあります。データが正しく変換されていない場合は、注釈かもしれない。

+0

私はそれらを入力しましたが、0,0にもありません。多分あなたは私にそれを解決するためのいくつかの他の方法を助言することができますか? –

+0

あなたのループの前に、viewDidLoadで 'NSLog(@" MapView is%@ "、mapview);を追加し、あなたが得るものを見てください。 – Rayfleck

+0

MapViewは> –

関連する問題