Closed jondoes closed 7 years ago
Can you provide the latitude / longitude pair you are using which returns no results? You only have one key which has a negative latitude so unless you are close to that value, nothing will be returned. Also, how are you adding items to your GeoFire index? Can you share the code for that please?
Thank you for your reply
I am using below latitude / longitude pair to fetch data. Latitude: 23.022505 Longitude: 72.5713621
Following code used to store data on firebase,
if let latitude = self.latitude, let longitude = self.longitude
{
var jsonDict = Dictionary<String, AnyObject>()
jsonDict[Global.dbKeys.locKey] = Global.dbKeys.locValue as AnyObject?
jsonDict[Global.dbKeys.locDictKey] = [Global.dbKeys.locDictLat : latitude, Global.dbKeys.locDictLong : longitude] as AnyObject?
registerBusinessInAllNodesDict["\(FirebaseDataService.ds.REF_GEOFIRE.child(childRef.key))".trimFirebaseHost()] = jsonDict as AnyObject?
}
Are you actually calling geoFire.setLocation()
at any point? That is how you are supposed to add data to your Firebase index. I don't see a call to that in the code you shared. That might be your problem.
My mistake was, I have not use geoFire.setLocation() method. By using this my issue got resolve. Thank you for support.
hey @jondoes , i have the same problem . I did everything discussed here but still onKeyEntered method not called only onGeoQueryReady method called and update marker in realtime .
I have the following database structure.
My firebase security rules are open (i.e. test mode) . And using "com.firebase:geofire-android:3.0.0" with other firebase dependencies : firebase-core:16.0.9 , firebase-auth:17.0.0 ,firebase-database:17.0.0 , firebase-ui-database:5.0.0 , firebase-storage:17.0.0
And here is my java code
DatabaseReference locationRef =
FirebaseDatabase.getInstance().getReference().child("Location").child(mUID);
GeoFire geoFire = new GeoFire(locationRef);
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mUser.latitude,mUser.longitude),1);
geoQuery.removeAllListeners();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
showMarker();
showNotification("Entered");
Log.d(TAG, "onKeyEntered: called ");
}
@Override
public void onKeyExited(String key) {
showMarker();
Log.d(TAG, "onKeyExited: called");
showNotification("Exited");
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
Log.d(TAG, "onKeyMoved: called");
}
@Override
public void onGeoQueryReady() {
Log.d(TAG, "onGeoQueryReady: called");
showMarker();
}
@Override
public void onGeoQueryError(DatabaseError error) {
}
});
Q. What i want to do ? Ans: I want user's to see live location of other by updating marker on map. And i want to show notification when user enters and exits a specific location (i.e mUser.lattitude and mUser.longitude) .
I hope you understand my problem .
@muankit did you find a solution ? I'm also facing same issue. please help me out
When I pass longitude as positive value then it not calling onKeyEntered() method. It directly call onGeoQueryReady() method even data available in radius. When I pass longitude as negative value then it is calling onKeyEntered() method.
My code is as below,
private DatabaseReference firebaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl("my_database_url");
private GeoFire geoFire = new GeoFire(firebaseRef.child("geofire"));
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(23.022505, 72.5713621), 1000);
My firebase data screen shot attached below.