當用戶給出起始地址和目的地址時,我已經使用Google方向AP計算緯度和經度。在這個api中,我也獲取了中點數的緯度和經度。我全部存儲在數組中。現在我想添加新數組中每個點的經度和緯度值。如何將它們的值存儲在數組中?當從XML獲取數據解析然後我使用此代碼如何在數組中添加數字的經緯度值?
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if (qName)
{
elementName = qName;
}
else if ([elementName isEqualToString:@"start_location"])
{
isFoundStartLoc = NO;
}
else if ([elementName isEqualToString:@"end_location"])
{
isFoundEndLoc = NO;
}
else if ([elementName isEqualToString:@"lat"])
{
if (isFoundStep)
{
if (isFoundStartLoc)
{
stepObject.startLocLat = [self.currentElement doubleValue];
}
else if(isFoundEndLoc)
{
stepObject.endLocLat = [self.currentElement doubleValue];
}
}
else{
if (isFoundStartLoc)
{
slegObject.startLocLat = [self.currentElement doubleValue];
}
else if(isFoundEndLoc)
{
slegObject.endLocLat = [self.currentElement doubleValue];
}
}
}
else if ([elementName isEqualToString:@"lng"])
{
if (isFoundStep)
{
if (isFoundStartLoc)
{
stepObject.startLocLong = [self.currentElement doubleValue];
}
else if(isFoundEndLoc)
{
stepObject.endLocLong = [self.currentElement doubleValue];
}
}
else{
if (isFoundStartLoc)
{
slegObject.startLocLong = [self.currentElement doubleValue];
}
else if(isFoundEndLoc)
{
slegObject.endLocLong = [self.currentElement doubleValue];
}
}
}
else if ([elementName isEqualToString:@"distance"])
{
isFoundDistance = NO;
}
else if ([elementName isEqualToString:@"text"])
{
if (isFoundStep)
{
if (isFoundDistance){
stepObject.distance=[self.currentElement doubleValue];
}
}
else
{
if(isFoundDistance)
{
slegObject.total_distance=[self.currentElement doubleValue];
}
}
}
else if ([elementName isEqualToString:@"step"])
{
if (ListofSteps1==nil)
{
ListofSteps1=[[NSMutableArray alloc]init];
}
[ListofSteps1 addObject:stepObject];
[stepObject release];
stepObject=nil;
isFoundStep=NO;
}
else if ([elementName isEqualToString:@"leg"])
{
if (listofPoint==nil)
{
listofPoint=[[NSMutableArray alloc]init];
}
[listofPoint addObject:slegObject];
[slegObject release];
slegObject=nil;
}
} 在此代碼我有兩個陣列上是listofPoint用於存儲僅緯度和源壞目的地點的經度。另一個是ListofSteps1,用於存儲源和目標中間點的緯度和經度。現在我想在一個數組中添加所有的經度和緯度。那麼如何在單個數組中存儲?
請發佈一些您的相關代碼。 – jtbandes
緯度和經度在浮動(或雙打)對不對? – Krishnabhadra
@ Krishnabhadra雙打 – iRam11