gpt4 book ai didi

iOS : alert user for specific Geo location area (lat, 长)

转载 作者:行者123 更新时间:2023-12-01 19:12:06 25 4
gpt4 key购买 nike

我正在尝试实现 Geo location 的功能对于用户,我正在静态设置 latitudelongitude信息,当应用程序启动时,如果用户在该区域内,我将显示一条消息“您已到达办公室”,否则“您将离开办公室”。我已经实现了下面的代码来实现这一点,我尝试通过步骤和车辆四处移动,但在这两种情况下它总是显示“你已经到达办公室”,但是我离那个位置 2 公里!我认为问题在于 CLLocationManager 中的地理数据比较代表。

- (void) startUpdateUserLocation
{
if(!locationManager)
locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

// [locationManager startUpdatingLocation];

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(latitude, longitude);

CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:kCLDistanceFilterNone identifier:@"identifier"];
[locationManager startMonitoringForRegion:region];
}

- (void)viewDidLoad
{
[super viewDidLoad];

latitude = 23.076289;
longitude = 72.508129;
}

- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

MKCoordinateRegion region;
region.center = mapView.userLocation.coordinate;
region.span = MKCoordinateSpanMake(0.25, 0.25);
region = [mapView regionThatFits:region];
[mapView setRegion:region animated:YES];

lblCurrentCoords.text = [NSString stringWithFormat:@"lat %f lon %f",mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];

[self startUpdateUserLocation];
}

- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0)
{
[listOfPoints addObject:manager.location];
[tablePoints reloadData];

/*
* locationManager:didEnterRegion:
*
* Discussion:
* Invoked when the user enters a monitored region. This callback will be invoked for every allocated
* CLLocationManager instance with a non-nil delegate that implements this method.
*/

lblLocationStatus.text = @"You're in office area!...";
}

- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0)
{
/*
* locationManager:didExitRegion:
*
* Discussion:
* Invoked when the user exits a monitored region. This callback will be invoked for every allocated
* CLLocationManager instance with a non-nil delegate that implements this method.
*/

lblLocationStatus.text = @"You're going out from office area!...";
}

- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_TBD,__IPHONE_5_0)
{
/*
* locationManager:didStartMonitoringForRegion:
*
* Discussion:
* Invoked when a monitoring for a region started successfully.
*/

lblLocationStatus.text = @"Start monitoring...";
}

- (void)locationManager:(CLLocationManager *)manager
monitoringDidFailForRegion:(CLRegion *)region
withError:(NSError *)error __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0)
{
/*
* locationManager:monitoringDidFailForRegion:withError:
*
* Discussion:
* Invoked when a region monitoring error has occurred. Error types are defined in "CLError.h".
*/

lblLocationStatus.text = @"Stop monitoring...";
}

我正在努力完成以下事情!
  • 如果用户输入了地理位置,他应该是“警觉的”。 --- 如何匹配位置?
  • 如果在该地理位置内四处移动,则代码应监控此事件! --- 需要设置所需的精度属性吗?
  • 我希望我的代码不断检查用户地理位置,我该怎么做? --- 需要调用NSTimer中的函数?

  • 我发现关于 SO 的许多问题都问了同样的问题,但没有人给出匹配的答案!有人请指导我是否朝着正确的方向前进,因为此代码未显示! :)

    最佳答案

    听起来您应该改用区域监控,它会告诉您用户何时进入或退出圆形区域。使用 startMonitoringForRegion: 进行设置并实现 CLLocationManagerDelegate方法

    – locationManager:didEnterRegion:
    – locationManager:didExitRegion:
    – locationManager:monitoringDidFailForRegion:withError:
    – locationManager:didStartMonitoringForRegion:

    如果您在输入错误的位置数据时遇到问题,请检查 CLLocation 的年龄在 locationManager:didUpdateLocations:locationManager:didUpdateToLocation:fromLocation: .如果超过 60 秒,请不要使用它。

    关于iOS : alert user for specific Geo location area (lat, 长),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15850232/

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