gpt4 book ai didi

ios - 位置更新问题 iOS

转载 作者:行者123 更新时间:2023-11-28 21:27:12 24 4
gpt4 key购买 nike

我知道有很多与此相关的问题,但我无法链接到我的问题。在我的应用程序中,我正在获取附近的餐厅,最初,如果用户单击“附近”按钮,我会使用下面的代码获取纬度、经度、地标详细信息。

-(void)setUpUserLocation
{
BOOL locationAllowed = [CLLocationManager locationServicesEnabled];
if (locationAllowed==NO)
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"No authorization"
message:@"Please, enable access to your location"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Open Settings", nil];
[alertView show];
}
else
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;

if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
}
[locationManager startUpdatingLocation];
}


-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location=[locations lastObject];
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = placemarks[0];
NSDictionary *addressDictionary = [placemark addressDictionary];

}];
[self stopSignificantChangesUpdates];

}
- (void)stopSignificantChangesUpdates
{
[locationManager stopUpdatingLocation];
locationManager = nil;
}

我的问题是,如果用户位置发生变化,我该如何向用户发出警告,例如 您的位置已更改,您需要更新它,然后您才能获得附近的餐厅 Location一旦用户位置发生变化,弹出窗口就应该出现,否则不想每次都调用 didUpdateLocation。我调用了 startMonitoringSignificantLocationChanges 然后它没有在第一次调用 didUpdateLocation 本身。对此有任何帮助。

最佳答案

一段时间后检查或在用户移动后检查(任何你想要的),如果条件为真则调用服务...

我觉得对你有帮助;

第一步

 (void)viewDidLoad {
[super viewDidLoad];

locationManager = [[CLLocationManager alloc] init];
//set the amount of metres travelled before location update is made
[locationManager setDistanceFilter:100];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

[locationManager requestAlwaysAuthorization];

// call the timer with 5 minutes cap using 5 * 60 = 300
[NSTimer scheduledTimerWithTimeInterval:300.0f target:self selector:@selector(sendlocation1) userInfo:nil repeats:YES];

第 2 步

每 100 米更换设备此方法称为:

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%f",newLocation.coordinate.latitude);

NSLog(@"%f",newLocation.coordinate.longitude);
CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];
if(meters >=100)
{
// call webservice for location is updated
[self sendlocation1];
}else
{
// call normal method
}
}

关于ios - 位置更新问题 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37628022/

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