Ios 从NSMutableArray获取值

Ios 从NSMutableArray获取值,ios,objective-c,Ios,Objective C,我正在开发ios应用程序和谷歌地图。在谷歌地图上画线,坐标附加在可变数组上,在NSUSERDEFAULT上保存的坐标数据保存得很好。但是当在NSUSERDEFAULT上获取数据并在谷歌地图上显示坐标时。但是在GMSMutablePath应用程序中,崩溃错误消息是exc_bad_access(代码=1,地址=0*4)。请提前帮助感谢 for (int i = 0; i < [coordinateArray count]; i++) { NSDictionary *dic =

我正在开发ios应用程序和谷歌地图。在谷歌地图上画线,坐标附加在可变数组上,在NSUSERDEFAULT上保存的坐标数据保存得很好。但是当在NSUSERDEFAULT上获取数据并在谷歌地图上显示坐标时。但是在GMSMutablePath应用程序中,崩溃错误消息是exc_bad_access(代码=1,地址=0*4)。请提前帮助感谢

for (int i = 0; i < [coordinateArray count]; i++) {
        NSDictionary *dic = [coordinateArray objectAtIndex:i];
        NSString *lat = [dic valueForKey:@"lat"];
        NSString *longitude = [dic valueForKey:@"long"];
        _valuePoints.latitude = [lat doubleValue];
        _valuePoints.longitude = [longitude doubleValue];
        GMSMutablePath *path = [[GMSMutablePath alloc]              initWithPath:self.polyline.path];
        [path addCoordinate:_valuePoints];
        self.polyline.path = path;
    }
for(int i=0;i<[coordinarray count];i++){
NSDictionary*dic=[Coordinatorray对象索引:i];
NSString*lat=[dic valueForKey:@“lat”];
NSString*经度=[dic valueForKey:@“long”];
_valuePoints.latitude=[lat doubleValue];
_valuePoints.longitude=[longitude doubleValue];
GMSMutablePath*path=[[GMSMutablePath alloc]initWithPath:self.polyline.path];
[路径添加坐标:_值点];
self.polyline.path=路径;
}

直接将坐标保存到阵列

[_arr addObject:coordinate]; 
NSLog(@"%@",_arr);
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
保存数组本身,而不是将值保存为字符串

[defaults setObject:_arr forKey:@"numberArray"]; 
[defaults synchronize];
从NSUserDefault读回数据时

NSArray *coordinateArray = [ud objectForKey:@"numberArray"];

从CoordinatorRay,您可以使用保存坐标的纬度和经度在对象之间循环以获取CLLocation对象。

能否显示将数据保存到NSUserDefaults的部分,以及解释预期的行为。谢谢。[\u arr addObject:[NSData dataWithBytes:&坐标长度:sizeof(坐标)];NSLog(@“%@”,_arr);NSUserDefaults*默认值=[NSUserDefaults standardUserDefaults];[默认设置对象:[NSString stringWithFormat:@“%@”,_arr]forKey:@“numberArray”];[默认同步];拯救coordinates@DeepakKumar,为什么你不应该编辑你的问题而不是发表评论。我的建议是,你更喜欢plist或任何json文件来保存坐标。