我试图从一个plist中加载的注释,并显示到地图,但具有麻烦坐标的对象:创建从一个plist中
一)分配的坐标动态,并
b)中的地图上显示它们。
当我物理分配lat和长像:
tempCoordinate.latitude = 53.381164;
tempCoordinate.longitude = -1.471798;
地图绘制与注释,但它似乎绘制他们都在同一个地方?
我一直在努力工作这么久,有没有更好的方法?任何帮助将不胜感激。我开始考虑手动将它们全部输入为对象。
这是我的plist ....
我想使2种类型的注释的每个所创建的作为对象,然后加入到单独的阵列,这样我可以在地图视图在它们之间切换。
这里是我的annotations.h类:
@property (copy) NSString *streetName;
@property (copy) NSString *bays;
@property (copy) NSString *type;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithAnnotationName:(NSString *)newStreetName
theBays:(NSString *)newBays
theType:(NSString *)newType
theCoordinate:(CLLocationCoordinate2D)newCoordinate;
这里是annotations.m:
if ((self = [super init])) {
type = [newType copy];
streetName = [newStreetName copy];
bays = [newBays copy];
coordinate = newCoordinate;
}
这里是mapView.h
parkingArray1 = [[NSMutableArray alloc] init];
//NSMutableArray *testArr = [[NSMutableArray alloc] init];
//path of plist
NSString *fullPathToPList=[[NSBundle mainBundle] pathForResource:@"AnnotationList" ofType:@"plist"];
//temp values for dictionary enumeration and creating annotation object
NSDictionary *plistDict, *BlueBadgeDict, *BlueBadgeContentsDict;
plistDict = [NSDictionary dictionaryWithContentsOfFile: fullPathToPList];
//enumerate through BlueBadge dictionary
BlueBadgeDict = [plistDict valueForKey: @"BlueBadge"];
for (NSString *firstLevelString in BlueBadgeDict){
BlueBadgeContentsDict = [BlueBadgeDict valueForKey:firstLevelString];
NSString *tempStreetName, *tempBays, *tempType, *tempLat, *tempLong;
CLLocationCoordinate2D tempCoordinate;
for (NSString *secondLevelString in BlueBadgeContentsDict){
//assign temp values from dict to string
if ([secondLevelString isEqualToString:@"StreetName"])
tempStreetName = [BlueBadgeContentsDict valueForKey:secondLevelString];
else if ([secondLevelString isEqualToString:@"Bays"])
tempBays = [BlueBadgeContentsDict valueForKey:secondLevelString];
else if ([secondLevelString isEqualToString:@"Longitude"])
tempLong = [BlueBadgeContentsDict valueForKey:secondLevelString];
else if ([secondLevelString isEqualToString:@"Latitude"])
tempLat = [BlueBadgeContentsDict valueForKey:secondLevelString];
}
//pass plist root value
tempType = firstLevelString;
tempCoordinate.latitude = [tempLat doubleValue];
tempCoordinate.longitude = [tempLong doubleValue];
//create object
Annotation *tempAnnotation = [[Annotation alloc] initWithAnnotationName:tempStreetName theBays:tempBays theType:tempType theCoordinate:tempCoordinate];
//add the object to the mutable array
[parkingArray1 addObject:tempAnnotation];
[tempAnnotation release];
}
//display array on map
[self.mapView addAnnotations:parkingArray1];
这里是XML代码
<dict>
<key>BlueBadge</key>
<dict>
<key>BB1</key>
<dict>
<key>Bays</key>
<string>4</string>
<key>Latitude</key>
<string>-1.466822</string>
<key>Longitude</key>
<string>53.37725</string>
<key>StreetName</key>
<string>Arundel Lane</string>
</dict>
<key>BB2</key>
<dict>
<key>Bays</key>
<string>5</string>
<key>Latitude</key>
<string>-1.471994</string>
<key>Longitude</key>
<string>53.381071</string>
<key>StreetName</key>
<string>Balm Green</string>
</dict>
<key>BB3</key>
<dict>
<key>Bays</key>
<string>1</string>
<key>Latitude</key>
<string>-1.466739</string>
<key>Longitude</key>
<string>53.374164</string>
<key>StreetName</key>
<string>Brittain Street</string>
</dict>
</dict>
</dict>
请将plist作为xml(如果很长,然后是一个小样本)发布并将其格式化为“代码”。 – Anna