【问题标题】:How to use Geoquery on another project with geofire real-time database in android?如何在另一个项目中使用 Geoquery 与 android 中的 geofire 实时数据库?
【发布时间】:2019-09-11 15:40:34
【问题描述】:

我有 2 个 firebase 项目,一个用于用户应用程序,第二个用于驱动程序应用程序。我将驱动程序应用程序的最新位置(经纬度)存储在 firebase 实时数据库中。现在我想从我的用户应用程序对驱动程序的项目数据库执行地理查询。我的问题是如何在另一个项目上执行地理查询。我想在地理查询的帮助下从用户应用程序中获取驱动程序列表(绕过用户的当前位置以查找附近的驱动程序)

    FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId("1:my_App_ID").setApiKey("AIza_My_API_KEY").setDatabaseUrl("https://My_URL.firebaseio.com/").build();   
    FirebaseApp.initializeApp(this , options);

    FirebaseApp app = FirebaseApp.getInstance("xyz");
    FirebaseDatabase secondaryDatabase FirebaseDatabase.getInstance(app);
    DatabaseReference data = secondaryDatabase.getInstance().getReference().child("Drivers Available");
    GeoFire geoFire = new GeoFire(data);
    GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(21.11626328, 79.051096406), 1);
    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            Log.d("test_geolocation",key);
        }

        @Override
        public void onKeyExited(String key) {}

        @Override
        public void onKeyMoved(String key, GeoLocation location) {}

        @Override
        public void onGeoQueryReady() {

        }
        @Override
        public void onGeoQueryError(DatabaseError error) {
            Log.d("errorGeoQuery",error+"");
        }
    });

【问题讨论】:

    标签: android firebase firebase-realtime-database maps geofire


    【解决方案1】:

    您需要为您的应用实例命名xyz,如果您以后想通过该名称查找它。

    比如:

    FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId("1:my_App_ID").setApiKey("AIza_My_API_KEY").setDatabaseUrl("https://My_URL.firebaseio.com/").build();   
    FirebaseApp.initializeApp(this , options, "xyz");
    
    FirebaseApp app = FirebaseApp.getInstance("xyz");
    

    另请参阅 using multiple projects in your application 上的 Firebase 文档。

    【讨论】:

      猜你喜欢
      • 2015-10-08
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 2016-11-15
      • 2012-09-14
      相关资源
      最近更新 更多