当用户指定了起点和目的地地址时,我已经使用Google Direction 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,用于存储源和目标中间点的纬度和经度。现在,我想将所有纬度和经度添加到单个数组中。那么如何存储在单个数组中?
如果只想将两个点都存储到一个数组中,则有几种可能性:
创建一个包含两个点作为一个元素的新类,并添加此类的实例(最有可能是最简洁的方式)]]
如果您始终为每个条目存储两个点,则只需添加这些点并通过arrayIndex = n*2; [myArray objectAtIndex: n] and [myArray objectAtIndex: n+1]
来访问nTh对。
3您还可以创建一个包含1点和一个属性的新类。但是,那么您需要始终从头开始遍历该列表(我不确定这是您想要的情况)
ps,您释放了slegObject。我看不到您为此执行了alloc / init。
您的问题是不是内存管理问题?