我試圖從一個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