0

我曾在一個應用程序名稱時間跟蹤器上工作。用戶可以手動輕掃並通過單擊按鈕手動輕掃。根據ios中的位置登錄和註銷捕獲

現在我想使它成爲基於位置檢測的自動化。爲此,我正在使用CLLocationManager類。它有時工作正常,有時它會給出錯誤的滑動​​細節。我使用下面的代碼。

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
     [locationManager requestWhenInUseAuthorization]; 

     [locationManager startUpdatingLocation]; 

}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 

    _latitude.text = [NSString stringWithFormat:@"Latitude: %f", newLocation.coordinate.latitude]; 
    _longitude.text = [NSString stringWithFormat:@"Longitude: %f", newLocation.coordinate.longitude]; 

    if([_latitude.text doubleValue] > 17.76890) && [_longitude.text doubleValue] > 78.34567) { 

     if (isSwipeIn) { 
      isSwipeIn = false; 
      //necessary swipe out UI and logic 
     } else { 
      isSwipeIn = true; 
      //necessary swipe in UI and logic 
     } 
    } 
} 

誰能幫我對這個..

回答

0

還有另一種方式來做到這一點,你可以從目標位置獲得距離和與當前位置的horizontalAccuracy檢查。

delta爲您提供當前位置和目標位置之間的距離。如果delta小於(<)horizontalAccuracy比當前位置在半徑爲horizontalAccuracy的圓中。

如果delta大於(>)horizontalAccuracy比當前位置遠遠超過您的目標位置。

所以現在CLLocationManager委託方法將看起來象下面這樣:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 

    _latitude.text = [NSString stringWithFormat:@"Latitude: %f", newLocation.coordinate.latitude]; 
    _longitude.text = [NSString stringWithFormat:@"Longitude: %f", newLocation.coordinate.longitude]; 

    // Create Location object for your target location. e.g. (17.76890,78.34567) 
    CLLocation *targetLocation = [[CLLocation alloc] initWithLatitude:17.76890 longitude:78.34567]; 
    CLLocationDistance delta = [newLocation distanceFromLocation:targetLocation]; 

    if (delta > newLocation.horizontalAccuracy) { 
     if (isSwipeIn) { 
      isSwipeIn = false; 
      //necessary swipe out UI and logic 
     } else { 
      isSwipeIn = true; 
      //necessary swipe in UI and logic 
     } 
    } 
} 
1

,而不是比較LAT-長的,去一個範圍檢查一樣,如果你的設備是幾米大關的刷卡範圍內另有刷卡了。

可以使用LAT-長在Objective-C

CLLocation *location; // Your Location to compare 
CLLocation *currentLocation; // Your current location 
double distance = [location distanceFromLocation:currentLocation]; // Returns distance in meters 

// Now lets say you are within 5 meters mark Swipe In 

if(distance <= 5) 
    // Mark swipe IN 
else 
    // Mark swipe OUT 

下面的方法兩者之間的距離檢查我希望這會幫助你。快樂編碼:)