我有两个位置,一个是司机,另一个是骑手,我有很长的时间可以使用这两个地方,我想当司机进入骑手位置的地理位置时,我想点击一个api。
我完成了QKGeofenceManager演示项目:使用它,我可以提供lat、n、long和半径来查找地理位置。
但问题是,每次在后台更新驱动程序位置以及应该应用什么条件,以便在驱动程序进入rider.If的地理区域时进行回调,ap处于后台,它将如何处理一切。我必须在appdelegate中做任何更改吗?
- (NSArray *)geofencesForGeofenceManager:(QKGeofenceManager *)geofenceManager
{
NSArray *fetchedObjects = [self.fetchedResultsController fetchedObjects];
NSMutableArray *geofences = [NSMutableArray arrayWithCapacity:[fetchedObjects count]];
for (NSManagedObject *object in fetchedObjects) {
NSString *identifier = [object valueForKey:@"identifier"];
CLLocationDegrees lat = [[object valueForKey:@"lat"] doubleValue];
CLLocationDegrees lon = [[object valueForKey:@"lon"] doubleValue];
CLLocationDistance radius = [[object valueForKey:@"radius"] doubleValue];
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(lat, lon);
CLCircularRegion *geofence = [[CLCircularRegion alloc] initWithCenter:center radius:radius identifier:identifier];
[geofences addObject:geofence];
}
return geofences;
}发布于 2016-05-09 11:46:19
我找到了一个替代方案来完成这项任务。由于没有调用我的Didenterlocation委托方法,所以我采用了另一种方法。
- (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.58171,77.2915457);
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);
}通过跟踪当前位置,每当当前位置坐标进入中心区域的坐标时,就可以发出用户已进入此特定区域的通知。
https://stackoverflow.com/questions/36997834
复制相似问题