2014-05-20 3 views
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]; 
} 

어떤 생각 :

다음은 현재 위치 및 지역 위치 사이의 거리를 계산하는 코드이다?

답변

3

이것은 모니터링 아이폰 OS 지역에서 결함 내가 지오 펜싱와 유사한 문제에 직면하고 내가 그 문제를 해결하는 방법을 발견했다.

나뿐만 아니라 그것에 대한 블로그 포스트를, 나는 여기에 질문을 게시하고 나 자신을 대답했다 : - 대답 리키

  1. Region Monitoring Glitch on iOS 7 - Multiple Notifications at the same time
  2. iOS Region Monitoring and Location Manager
+1

감사합니다. 현재 위치 및 지역을 확인하도록 제안 했으므로 거리 계산을 통해이를 수행했습니다. 위치 관리자의 잘못된 행동에 대한 이유를 찾았습니까? – OMK

+1

문제 없습니다. ** [theRegion containsCoordinate : theLocationCoordinate]; **를 사용하여 이벤트를 트리거하기 전에 영역 내에 실제로 있는지 확인할 수 있습니다. 나는 다양한 웹 사이트에서 위아래로 수색했으며, 나는 아무것도 찾을 수 없었다. 나는 그것이 특정 국가에서 발생할 수있는 큰 반경 (정확도)이있는 나쁜 위치 때문일 것으로 생각합니다. 이 힘든 일을 나는 확신 할 수 없다. – Ricky