ios - 在 iOS 数据库中存储和更新 Lat Long 值

标签 ios objective-c database

我在我的应用程序中使用 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;
}

现在我的任务是在用户单击“提交”按钮后,我想在本地存储这些经纬度。如果用户想要更新点,我想更新(添加/删除)数据库中的那些点和与经纬度相关的标记,并将它们再次保存在数据库中。 谁能帮帮我。

最佳答案

要存储包含 5 个纬度/经度值的数组,您需要执行以下操作:

[[NSUserDefaults standardUserDefaults] setObject:markeyArray forKey:YOUR_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];

然后当您想要检索它们时:

NSArray *myArray = [[NSUserDefaults standardDefaults] objectForKey:YOUR_KEY];

至于从坐标中获取地址,您应该研究反向地理编码。

关于ios - 在 iOS 数据库中存储和更新 Lat Long 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22910492/

相关文章:

ios - 哪个是在 MVP 模式(swift)中初始化演示者的最佳方式

ios - UITableViewCell accessoryType UITableViewCellAccessoryCheckmark 重复

ios - 如何控制 UITextField 的复制和粘贴弹出位置?

android - 从适用于 Android 的 sqlite 数据库中存储和检索 blob

ios - 您什么时候会在推送负载中使用 "thread-id" key ?

ios - 如何在 iOS 中上传大视频?

ios - 添加 SCNBillboardConstraint 使节点消失

ios - 在 UILabel et.al 中使用 NSString 子类

sql - 使用外键,可以引用列和固定值吗?

database - 部件号字段的原子性