gpt4 book ai didi

iphone - iOS:使用 CLLocationManager 获得准确的反向地理编码?

转载 作者:行者123 更新时间:2023-11-29 13:37:34 27 4
gpt4 key购买 nike

背景:我想让用户在需要时在几秒钟内获得他们的位置。但是,该位置大多不准确。我想询问用户是否愿意再试一次以获得更准确的地址。

问题如何编写代码以保证下一次猜测总是比上一次猜测好。

我尝试过的:

CLLocationManager *locationManager;

- (CLLocationManager *)locationManager {
if (locationManager != nil) {
return locationManager;
}
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
return locationManager;
}

-(void)myLocationClickedWithCount: (int) count{
[[self locationManager] startUpdatingLocation];
CLLocation *location = [locationManager location];
CLGeocoder *locationGeocoded = [[CLGeocoder alloc] init];
[locationGeocoded reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
if (!placemark){
if (count > 0){
//placemark not available, try again after 1 second
sleep(1);
[self myLocationClickedWithCount:count-1];
}
else{
//Unable to get location after 3 tries
UIAlertView *locationNotFoundAlert = [[UIAlertView alloc]initWithTitle:@"Unable to Locate" message:@"Would you like to try again?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
locationNotFoundAlert.tag = locationNotFoundAlertTag;
[locationNotFoundAlert show];
}
}else{
// got location but not accurate.
if (location.horizontalAccuracy > accuracyRadius) {
UIAlertView *locationInaccurateAlert = [[UIAlertView alloc]initWithTitle:@"Inaccurate Location" message:[NSString stringWithFormat:@"Your GPS shows the radius of %.2f meters. Would you like to try again?",location.horizontalAccuracy] delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
locationInaccurateAlert.tag = locationInaccurateAlertTag;
[locationInaccurateAlert show];
}else {
address.text = placemark;
}
}
}];
}

更新当用户再次询问时,猜测可能需要更长的时间。我只想知道我应该如何编码。 IE:我应该再次调用 [[self locationManager] startUpdatingLocation]; 吗?还是会重置我目前的位置。因此,我如何根据 GPS 的当前信息第二次改进我的猜测(GPS 打开的时间越长,精度越高,对吗?)。

最佳答案

关于通过代码的准确性,您无能为力......除了

   [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

你已经做了...据我所知,如果您使用的是 3G 或 EDGE,那么您的精度会大大提高(可以达到 5-10 米的精度水平)。

可以引用this Apple 的文章讨论了 iPhone GPS 精度的工作原理......

希望这有帮助..

关于iphone - iOS:使用 CLLocationManager 获得准确的反向地理编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10127405/

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