Я просто пытаюсь показать, как далеко пользователь находится от местоположения, но мне кажется, что я ничего не могу напечатать на моей консоли. Если я помещу код в viewDidLoad и вручную введу координаты для "postLocations"
Я получил расстояние, но, похоже, ничего не напечатал с кодом, который у меня есть на данный момент.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation: CLLocation = locations[0] as CLLocation
let ref = Database.database().reference().child("posts")
ref.observeSingleEvent(of: .value, with: { (snapshot) in
guard let dictionary = snapshot.value as? [String: AnyObject] else { return }
guard let latitude = dictionary["latitude"] as? Double else { return }
guard let longitude = dictionary["longitude"] as? Double else { return }
let currentLocation = Coordinate(long: userLocation.coordinate.longitude, lat: userLocation.coordinate.latitude)
let postLocations = Coordinate(long: longitude, lat: latitude)
if currentLocation.distance(to: postLocations) <= 100 {
print("You are \(currentLocation.distance(to: postLocations)) away from posts")
} else {
print("No posts in area")
}
}) { (error) in
print("There was an error getting posts", error)
}
}
