Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query.observe doesn't seem to fire #146

Open
CLynch99 opened this issue Mar 14, 2021 · 2 comments
Open

Query.observe doesn't seem to fire #146

CLynch99 opened this issue Mar 14, 2021 · 2 comments

Comments

@CLynch99
Copy link

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)
    }
}

}
`

@joemerritt
Copy link

I'm having the same issue. It seems to fire ok when initially loading, then it when I pull another view above the Map and then minimize it seems to stop, .observe still keeps working though.

@joemerritt
Copy link

UPDATE: This seems to be a timing problem??? when initially loading the screen it doesn't work. However, after some time it works the way it should? Connor are you experiencing the same or have any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants