gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:04:44 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com