I am creating an Android App , an Uber Clone. In this I am using Firebase to list the rides created by the user.
The Ride stored in the following format .
{
"category" : "NUVO",
"driverids" : "",
"drop_lat" : "40.7127753",
"drop_long" : "-74.0059728",
"estdate" : "Wed@Feb@28th",
"estmile" : "4.19",
"esttime" : "01:02@PM",
"esttotalfare" : "4.61",
"fareest" : "1.1",
"g" : "t9z83wv46x",
"l" : [ 40.674426, -73.944033 ],
"notes" : "Gv",
"orgin_lat" : "145 Brooklyn Ave, Brooklyn, NY 11213, USA%20New York, NY, USA",
"request_id" : "5a75579740d166e95b8b4567",
"requested_category" : "FAM_SUV",
"rider_id" : "5a507bf340d16660288b4567",
"status" : 1,
"trip_id" : 0
}
Now I am Using GeoFire's GeoQuery's queryAtLocation to pick all rides with in 5 KMs from his current location.
The query uses the lat & lang from the field "l" and compare it with the current location lat & lang of the driver.
If the list's lat & lang is within 5 KMs , it will return the key , that is the parent name of the child "l".
Now I am currently in India. I use Lockito App to fix a Mock GPS location in India. After that I create a Ride within 5 KMs radius.
Now , the ride successfully listed in the drivers list. No Problem.
My Issue
But When I fix a mock GPS location in USA , this flow not working. I fixed the driver location on Brookyln Childeren's Museum and also created a ride on the same museum. But GeoQuery not calling onKeyEntered . It simply exists after calling GeoQueryReady function .
I check my current Lat & Lang from the app and it returns as 40.67434763453142,-73.94402358680964
. I checked this against the lat&lang on field "l" .(refer above JSON). Both pointing to same location.
But GeoQuery failed to retrieve it
My Question Why this issue happening ?. If I use India's locations. Geoquery works perfectly .
But why it failing in USA.
You may tell ,"There will be an issue in lockito". But Lockito returning correct location lat lang . I checked it in Logcat. And , if there is a issue in Lockitto then How it working in India.
Here My GeoQoery Code :
try {
showDialog();
double nearByDistanceRadius = 5.00d;
com.firebase.geofire.GeoFire geoFire = new com.firebase.geofire.GeoFire(FirebaseDatabase.getInstance().getReference().child(childtype));
final com.firebase.geofire.GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), nearByDistanceRadius);
geoQueryEventListener=new GeoQueryEventListener() {
@Override
public void onKeyEntered(final String key, GeoLocation location) {
Toast.makeText (getApplicationContext(), "The key is = ",Toast.LENGTH_LONG).show();
}
@Override
public void onKeyExited(final String key) {
System.out.println("ON KEYEXITED"+key);
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
System.out.println("ON KEYMOVED"+key);
}
@Override
public void onGeoQueryReady() {
System.out.println("ON KEYQUERYREADY");
@Override
public void onGeoQueryError(DatabaseError error) {
System.out.println("ON KEYERROR"+error);
}
};
geoQuery.addGeoQueryEventListener(geoQueryEventListener);
} catch (Exception e) {
e.printStackTrace();
}
Above , except onGeoQueryReady
, no method called if I use USA. But it's
working in India. Can anyone tell me why that is the case?
答案 0 :(得分:1)
这可能早已尘土飞扬,但也许可以帮助其他人。 自从你提到了它的模拟GPS坐标。您可能手动输入了它们。
GeoFire使用特殊的g:“代码”(10位数字代码),按地区/城市区分
如果您在相同的城市/国家(在您的情况下为印度)中使用相同的g代码,则可以正常使用! 但是,如果您在另一个国家/地区使用相同的代码,则geoQuery将失败。使它工作。您需要在代码中添加一行 geoFire.SetLocation()和美国境内的某个人只需运行一次该代码。 geoFire将在g:“” Location中保存一个特殊键。获得密钥后,您可以从应用程序中删除该行。 您可以使用geoFire生成的密钥在美国手动输入所需的任意位置,geoQuery始终可以在该位置使用!确保使用与geoFire相同的模式。 G: l: 0: 1:
答案 1 :(得分:-2)
花了一段时间,但我想。这就是有问题的 geofire 依赖。从3.0.0降级到2.3.1解决了。