1

As someone new to the above, I am struggling to use the location details stored in Firebase to display all user co-ordinates within Google Maps. Currently, the app displays the user, and no-one else.

I have looked at these questions:

How to query nearest users in Firebase with Swift?

GeoFire Swift 3 - Saving and Updating Coordinates

Firebase Retrieving Data in Swift

But unlike these, I only log the actual locations (for now), and am not interested in showing locations within a radius, but rather all those stored.

Below is the main section:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let location = locations.last

    let lat = location?.coordinate.latitude
    let long = location?.coordinate.longitude

    let ref = Database.database().reference().child("user_locations")
    let geoFire = GeoFire(firebaseRef: ref)
    geoFire.setLocation(location!, forKey: deviceUID) //using device ID as yet to add users

    let camera = GMSCameraPosition.camera(withLatitude: (lat)!, longitude:(long)!, zoom:14)
    self.mapView.animate(to: camera)

}

And this is what I've considered in locationManager, but don't know how to apply, or use without a radius:

    let center = CLLocation(latitude: lat!, longitude: long!)
    let circleQuery = geoFire.query(at: center, withRadius: 5)

    _ = circleQuery.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
    print("Key '\(key)' in area at location '\(location)'")

Any help would be appreciated.

Tim
  • 583
  • 1
  • 6
  • 18

0 Answers0