这是我第一次使用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.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";
annot1.subtitle=@"Address of title";
annot1.coordinate = CLLocationCoordinate2DMake(21.946114, 120.792778);
[mapView addAnnotation:annot1];
我为其中的3000人做了这个,但他们跑得很慢,所以我想找到一个更好的方法
答案 0 :(得分:0)
试试这个。
变化:
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的位置,如果您的数据未正确转换,那么您的注释可能会在哪里是