Skip to content

Query.observe doesn't seem to fire #146

@CLynch99

Description

@CLynch99

I'm not quite sure what is going on, so I would appreciate any recommendations. I am trying to update businesses to the screen as the user walks down the street (through the emulator). The businesses appear as the user is in close proximity, but the exit query doesn't seem to fire when the markers are out of proximity. I'm not sure why this is the case. Also, if you have any recommendations for what I should do I would appreciate it.

  `    
  let geofireRef = Database.database().reference()
  let geoFire: GeoFire
     
  var businessAnno = [String:MKAnnotation]()
      
  var annotations = [MKAnnotation]()
        
  init(_ control: MapView) {
          self.control = control
          self.center = control.center
          self.geoFire = GeoFire(firebaseRef: geofireRef.child("business_locations"))
  }
  
  func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
          setupListener(mapView)
  }

  func setupListener(_ mapView: MKMapView){
    
    let query = geoFire.query(with: MKCoordinateRegion(center: center.coordinate, latitudinalMeters: 250, 
    ### ### **longitudinalMeters:** 250))
    
    query.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
        print("Enter: \(key!)")
        let annotation = MKPointAnnotation()
        
        annotation.title = key
        annotation.coordinate = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: 
        location.coordinate.longitude)

        annotations.append(annotation)
        mapView.addAnnotation(annotation)

    
    query.observe(.keyExited, with: { (key: String!, location: CLLocation!) in
        print("Exit: \(key!)")

    query.observeReady {
        self.annotations.append(contentsOf: annotations)
    }
}

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions