ios - 如何将一个区域的地理围栏添加到监控中。

标签 ios objective-c location mapkit geofencing

- (void)locationManager:(CLLocationManager *)manager

     didUpdateLocations:(NSArray *)locations {

    // If it's a relatively recent event, turn off updates to save power
    NSLog(@"%@ locations",locations);

    float Lat = _locationManager.location.coordinate.latitude;
    float Long = _locationManager.location.coordinate.longitude;

    NSLog(@"Lat : %f  Long : %f",Lat,Long);

    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(28.52171,77.2015457);

    NSLog(@"center check %@",center);
    CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center
                                                                 radius:500
                                                             identifier:@"new region"];
    BOOL doesItContainMyPoint = [region containsCoordinate:CLLocationCoordinate2DMake(Lat,Long)];

    NSLog(@"success %hhd", doesItContainMyPoint);

}

问题是,这里我提供了一个我正在检查的静态区域(中心) 但要求是,该区域将占用骑手的经纬度,并且骑手的数量可以有所不同

i hv all lat n long 在一个字典数组中。首先,驾驶员将选择列表中的第一个骑手,那时我需要骑手 1 位置的区域。 我不知道如何实现这一目标

如果我喜欢这样

for (NsMutableDictionary * dict in goersList)
    {
        rider_id=[dict valueForKey:@"trip_id"];
        lat=[dict valueForKey:@"origin_lat"];
        longi=[dict valueForKey:@"origin_long"];

}

那么它如何知道要监视第一个区域,并且在从该范围存在后我会检查第二个位置

最佳答案

您可以动态创建区域并将它们添加到监控中。

for (NSDictionary *dict in [result valueForKey:@"Geofences"])
{
    NSLog(@"%@",dict);
    CLLocationCoordinate2D locationCoordinate=CLLocationCoordinate2DMake([[dict valueForKey:@"cLatitude"]doubleValue], [[dict valueForKey:@"cLongitude"]doubleValue]);

    CLCircularRegion *circularRegion=[[CLCircularRegion alloc]initWithCenter:locationCoordinate radius:[[dict valueForKey:@"Radius"]doubleValue] identifier:[dict valueForKey:@"Name"]];

    circularRegion.notifyOnEntry=YES;
    circularRegion.notifyOnExit=YES;
    [[AppDelegate sharedDelegate].locationManager startMonitoringForRegion:circularRegion];
    NSLog(@"%@",[[[AppDelegate sharedDelegate] locationManager].monitoredRegions description]);
}

这里有几个区域加入监控。您可以一次添加一个。即关于选择 TableView 。

并使用下面的代码删除其他的

for (CLRegion *monitored in [[AppDelegate sharedDelegate].locationManager monitoredRegions])
{
    [[AppDelegate sharedDelegate].locationManager stopMonitoringForRegion:monitored];
}

关于ios - 如何将一个区域的地理围栏添加到监控中。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37114342/

相关文章:

html - 在父窗口中打开 iFrame 中的链接(无法控制子站点)

ios - UITableView not loading data on app load//无法成功查询UITableViewCells的相关照片

ios - 是否可以使用 URL 方案(FaceTime 链接)启动 Group FaceTime 通话?

算法:将可加入游戏的用户与离他最近的用户匹配

iOS : Where to start for AliPay integration?

ios - 如何使用 AFN 3.0 保存响应并将该响应中的特定参数发送到服务器?

IOS/objective-C :EventKit EKReminders compared with EKEvents

objective-c - 移除 applicationDidEnterBackground 中的 uialertview

iOS 等待位置管理器初始化

google-chrome - 在 Chrome 上持续模拟 GPS 位置