My coding (as you will see) and familiarity with Xcode and Swift is basic, but I'm learning... I realize my nesting of the code isn't the greatest, if good at all. I am trying to integrate GeoFire within my Xcode 10 app. I have looked for a clear explanation, but I am still yet to find an answer. I have a registrationForm to register users. The initial Firebase setup was straightforward, and I have a fully functional form that registers the user in Firebase. Now I am trying to add GeoFire in order to track the user's location.
I have tried a bunch of approaches from YouTube videos and websites, none of which work.
import UIKit
import Foundation
import CoreLocation
import Firebase
import GeoFire
class SecondViewController: UIViewController {
//Firebase DB ref
var refDriver: DatabaseReference!
@IBOutlet weak var name: UITextField!
@IBOutlet weak var employeenumber: UITextField!
@IBOutlet weak var label: UILabel!
@IBAction func submit(_ sender: UIButton) {
addDriver()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//configuring firebase and ensures no error is returned
if(FirebaseApp.app() == nil){
FirebaseApp.configure()
}
//getting a reference to the node driver
refDriver = Database.database().reference().child("driver");
}
func addDriver(){
//generating a new key inside driver node
//and also getting the generated key
let key = refDriver.childByAutoId().key
//creating driver with the given values
let driver = ["id":key,
"name": name.text! as String,
"employeenumber": employeenumber.text! as String
]
//adding the driver to Firebase
refDriver.child(key!).setValue(driver)
//displaying submit message
label.text = "You are registered."
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
hey try importing the module after you install the pod
in
viewdidLoad()function call thesetupGeofire()in setupGeoFire i made a var geoFireRef this is just the node you want to save your users location info
then we make the geoFire object by passing in that node location, our geoFireRef var
then just making the geoFire object accessible everywhere using ``` self.geoFire = geoFire`` `
if you want to get users in a specific radius (km) you can check the func below too
Here is my User.swift Data Model