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

No response while calling Geofire.initialize on firebase realtime database #26

Closed
jesussmile opened this issue Jul 13, 2021 · 2 comments

Comments

@jesussmile
Copy link

In my realtime database I have correctly set up the Location for availableDrivers as shown in the picture below

Geofire.setLocation(
       currentFirebaseUser.uid, position.latitude, position.longitude);
   rideRequestRef.onValue.listen((event) {});

Now I want to query this location but for some reason, I get no response and no error from the database, I can't figure out what is wrong, My position of latitude and longitude is within the 50 km radius of the availableDrivers lat long ? Do I need to add anything more to my code below ? Is it an issue with the path? Do I need to specify the url to availableDriver if so how?
enter image description here

 Future<void> initGeoFireListener() async {
    print("drivers initiation");
    String pathToReference = "availableDrivers";

    Geofire.initialize(pathToReference);
    print("Drivers  ${initPosition.latitude}   ${initPosition.longitude}");
    try {
      Geofire.queryAtLocation(
              initPosition.latitude, initPosition.longitude, 50) //10 km
          .listen((map) {
        print("drivers map: $map");
        if (map != null) {
          print("drivers is not null");
          var callBack = map['callBack'];

          switch (callBack) {
            case Geofire.onKeyEntered:
              NearByAvailableDrivers nearByAvailableDrivers =
                  NearByAvailableDrivers(
                      map['key'], map['latitude'], map['longitude']);
              GeoFireAssistant.nearByAvailableDriversList
                  .add(nearByAvailableDrivers);
              if (nearbyAvailableDriverKeysLoaded == true) {
                updateAvailableDriversOnMap();
              }
              break;

            case Geofire.onKeyExited: //when any driver is offline
              //keysRetrieved.remove(map["key"]);
              GeoFireAssistant.removeDriverFromList(map['key']);
              updateAvailableDriversOnMap();
              break;

            case Geofire.onKeyMoved: //as driver position change
              NearByAvailableDrivers nearByAvailableDrivers =
                  NearByAvailableDrivers(
                      map['key'], map['latitude'], map['longitude']);

              GeoFireAssistant.updateDriverNearByLocation(
                  nearByAvailableDrivers);
              updateAvailableDriversOnMap();
              break;

            case Geofire.onGeoQueryReady:
              print(map['result']);

              break;
          }
        } else {
          print("Drivers Null");
        }

        //setState(() {});
      }).onError((error) {
        print("Drivers error $error");
      });
    } on PlatformException {
      print("Drivers : No platformException response");
    }
  }

Realtime database rules

{
      "rules": {
        ".read":true,
        ".write": true,
          "availableDrivers": {
          ".indexOn": ["g"]
        }
      }
    }   
@jesussmile
Copy link
Author

Resolved

@abdimussa87
Copy link

How were you able to resolve this issue

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