Ios 从plist加载的注释未显示

Ios 从plist加载的注释未显示,ios,mkmapview,plist,Ios,Mkmapview,Plist,这是我第一次使用plist。我一直在四处浏览,找不到其他帮助 我的viewDidLoad中有下面的代码。为什么我的注释没有显示出来 mapView.showsUserLocation = YES; mapView.delegate=self; NSMutableArray *annotations = [[NSMutableArray alloc]init]; NSString *path = [[NSBundle mainBundle] pathForResource:@"Stat

这是我第一次使用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];
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"; 
annot1.subtitle=@"Address of title"; 
annot1.coordinate = CLLocationCoordinate2DMake(21.946114, 120.792778); 
[mapView addAnnotation:annot1]; 
我为其中3000人做了这个,但是他们跑得很慢,所以我想找到一个更好的方法

更改:

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

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


另外提示:检查赤道几内亚西南部大西洋南部的注释-这是{0,0}的Lat/Lon所在的位置,如果数据转换不正确,这就是注释所在的位置。

第一个NSLog显示了多少注释?尝试记录lat和long值,以确保它们是正确的。确保mapView不是零。还有,[MyAnnotation release];应该是[myAnnotation release];。抱歉,也许我太新手了,无法理解你所问的部分内容,但这是从第一个NSlog中得出的:{Address=\U5f70\U5316\U7e23\U798f\U8208\U9109\U6cbf\U6d77\U8def\U56db\U6bb5256\U865f;纬度=24.035067;经度=120.419800;Name=\U53f0\U5851\U77f3\U6cb9;}大约有2000多个。当我硬编码它时,它显示得非常好,但是一旦我使用这个plist,它就消失了。mapView肯定不是零,我确实将我的更改为。感谢您的帮助,并期待您的更多帮助。谢谢还是你推荐其他人来做?多谢各位@安娜·卡列尼娜测试时,只需在plist中添加3个注释。在addAnnotation行之后,放置以下内容:NSLog@mapView.annotCount=%d,myAnnotation.coordinate=%f,%f,mapView.annotations.count,myAnnotation.coordinate.latitude,myAnnotation.coordinate.longitude;并查看打印内容。临时更改MyAnnotation*MyAnnotation=[[MyAnnotation alloc]init];到MKPointAnnotation*myAnnotation=[[MKPointAnnotation alloc]init];然后添加该NSLog。发生了什么?我输入了它们,但它们也不在0,0中。也许你可以给我一些其他的建议来解决这个问题?在viewDidLoad中,在循环之前,添加NSLog@MapView is%@,MapView;看看你得到了什么。MapView是非常奇怪的,因为当我硬编码它时,它工作得很好,但一旦我切换到plist,它就不会加载了。你有没有尝试在for循环中使用CLLocationCoordinate2DMake?
     float realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] floatValue];
     double realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] doubleValue];
     NSLog(@" double lat value is %f",realLatitude);