【发布时间】:2025-12-05 17:30:01
【问题描述】:
我在我的应用程序中使用 Google Maps iOS SDK。如果用户在某个位置长按获取 Lat Longs 的地址并将它们存储在一个数组中并将该数组加载到 UITableView 中,我编写下面的代码来获取特定地点的纬度和经度。
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:fullScreenRect];
[self.view addSubview:scroll];
scroll.contentSize=CGSizeMake(320,1000);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:17.3600
longitude:78.4760 zoom:9 ];
map = [GMSMapView mapWithFrame:CGRectMake(0,0, self.view.frame.size.width,390) camera:camera];
[scroll addSubview:map];
self->map.delegate = self;
tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 405, self.view.bounds.size.width, 250) style:UITableViewStylePlain];
[scroll addSubview:tab];
tab.delegate = self;
tab.dataSource = self;
markerArray = [[NSMutableArray alloc]init];
addressArray = [[NSMutableArray alloc]init];
}
- (void)mapView:(GMSMapView *)mapViewdidLongPressAtCoordinate(CLLocationCoordinate2D)coordinate
{
if([markerArray count]>=5)
{
UIAlertView *al = [[UIAlertView alloc]initWithTitle:@"Sorry" message:@"U Have Already Added 5 Favourite Locations" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[al show];
}
else
{
NSLog(@"%f",coordinate.latitude);
NSLog(@"%f",coordinate.longitude);
l1 = coordinate.latitude;
l2 = coordinate.longitude;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
marker.appearAnimation = YES;
marker.map = mapView;
[markerArray addObject:marker];
[self location];
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [addressArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc ]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [addressArray objectAtIndex:indexPath.row];
return cell;
}
现在我的任务是在用户单击“提交”按钮后,我想在本地存储这些经纬度。并且如果用户想要更新我想要从数据库中更新(添加/删除)这些点以及与该 Lat longs 相关的标记并将它们再次保存在数据库中。 谁能帮帮我。
【问题讨论】:
-
我猜首先你需要决定你希望使用什么类型的数据持久化:Core Data、SQLite、Plist……,听起来你好像还没有想到这个?
-
@Nick 我想使用核心数据存储它们。
-
那你有没有研究过Core Data?
-
是的,我知道核心数据。我的问题是我第一次将数组数据加载到表中,如果我更新该表,我无法将更新后的数据存储到数据库中。
标签: ios objective-c database