0
我想知道是否有方法來檢查用戶是否確實在特定位置(或可能在50-100英尺內)。我有一個CLLocationCoordinate2D
定義,我知道我可以檢查我的mapView.userLocation.coordinate.latitude
和mapView.userLocation.coordinate.longitude
,但我不知道什麼是最好的方法來檢查這將是。如何檢查用戶是否在iOS的指定緯度/經度?
我想知道是否有方法來檢查用戶是否確實在特定位置(或可能在50-100英尺內)。我有一個CLLocationCoordinate2D
定義,我知道我可以檢查我的mapView.userLocation.coordinate.latitude
和mapView.userLocation.coordinate.longitude
,但我不知道什麼是最好的方法來檢查這將是。如何檢查用戶是否在iOS的指定緯度/經度?
基本上你只需要比較緯度和計算距離。幸運的是,iOS在CLLocation
類中有一個內置方法。
這是一個簡單的方法來做到這一點。
CLLocation* location = [[CLLocation alloc] initWithLatitude:marker.coordinate.latitude longitude:marker.coordinate.longitude];
CLLocationDistance distance = [location distanceFromLocation:userLocation];
返回的值是米,你可以很容易轉換成英尺或測量的其他單位,你有興趣。
這裏是reference
驚人的文檔。謝謝! –