4
제 애플리케이션에서 지오 펜싱을 원합니다. 지오 펜싱 영역을 설정하는 위치 목록이 있습니다. 모든 위치의 반경은 100m입니다. 다음 코드를 설정하는 지역입니다 :지오 펜싱이 제대로 작동하지 않습니다.
CLLocationCoordinate2D cord;
cord.latitude = [location.latitude doubleValue];
cord.longitude = [location.longtitude doubleValue];
CLLocationDistance regionRadius = location.radius;
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:cord radius:regionRadius identifier:[NSString stringWithFormat:@"%d",location.locId]];
[appDelegate.locationManager startMonitoringForRegion:region];
내 문제는 제대로 작동하지 않는다는 것입니다. 디버깅을 위해 didEnterRegion 델리게이트는 현재 위치와 지역 위치 사이에 거리 계산을 더했습니다.이 거리는 1500m 이상입니다. -locationManager:didEnterRegion:
GET 같은 길을 잘못 트리거 왜
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
CLLocation *loc1 = locationManager.location;
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];
double dist = [loc1 distanceFromLocation:loc2];
}
어떤 생각 :
다음은 현재 위치 및 지역 위치 사이의 거리를 계산하는 코드이다?
감사합니다. 현재 위치 및 지역을 확인하도록 제안 했으므로 거리 계산을 통해이를 수행했습니다. 위치 관리자의 잘못된 행동에 대한 이유를 찾았습니까? – OMK
문제 없습니다. ** [theRegion containsCoordinate : theLocationCoordinate]; **를 사용하여 이벤트를 트리거하기 전에 영역 내에 실제로 있는지 확인할 수 있습니다. 나는 다양한 웹 사이트에서 위아래로 수색했으며, 나는 아무것도 찾을 수 없었다. 나는 그것이 특정 국가에서 발생할 수있는 큰 반경 (정확도)이있는 나쁜 위치 때문일 것으로 생각합니다. 이 힘든 일을 나는 확신 할 수 없다. – Ricky