Я использую GeoFire
в своем приложении, чтобы получить местоположения вокруг пользователя location
и иметь возможность отображать это на карте.Я хочу установить периметр в каждом месте, чтобы пользователь мог зарегистрироваться в этом конкретном радиусе.Я прочитал документацию GeoFire
, но мне немного сложнее понять, как реализовать метод .observe
, чтобы получить все ключи из локаций.Я пробую разные способы получения местоположения, но кажется немного сложнее, потому что ничего не обновлено до недавнего Swift
.
Мой Firebase
это:
Это мой код для выполнения метода .observe
:
import UIKit
import MapKit
import CoreLocation
import FirebaseCore
import Firebase
import FirebaseDatabase
import GeoFire
class MainController: UIViewController, MKMapViewDelegate ,CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
//Variables with reference in Firebase and Location Manager
var locationManager : CLLocationManager!
var ref: DatabaseReference!
let annotation = MKPointAnnotation()
//Store variables
var userLon = Double()
var userLat = Double()
var placeLon = Double()
var placeLat = Double()
//This is the loading on the app, everything adding in here will executed!
override func viewDidLoad() {
super.viewDidLoad()
//Calling the function to access and retrieving the user location
locationPermissions()
//retrievingLocation()
}
func retrievingLocations() {
let rootRef = Database.database().reference()
let geoRef = GeoFire(firebaseRef: rootRef)
let center = CLLocation(latitude: userLat, longitude: userLon)
let circleQuery = geoRef.query(at: center, withRadius: 10)
circleQuery.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
//This is not printing anything in my console
print("Key '\(key)' entered the search area and is at location '\(location)'")
})
}
Если есть что-то, что мне нужно предоставить, дайте мне знать, что я не хочу публиковать свои locationManager
код, потому что только доступ к местоположению и хранение всего в моих var
userLat
и userLon
Спасибо!
[1]: