【问题标题】:How to find location in database from my current location?如何从我当前的位置查找数据库中的位置?
【发布时间】:2019-01-29 09:29:47
【问题描述】:

所以现在我有半径为 1000 米的当前位置,所以我希望显示距离我当前位置 1000 米半径范围内的数据库中的所有位置。

geoFire.setLocation("You", new GeoLocation(latitude, longtitude),
                                new GeoFire.CompletionListener() {
                                    @Override
                                    public void onComplete(String key, DatabaseError error) {
                                        //Add Marker
                                        if(mCurrent != null)
                                            mCurrent.remove(); // Remove old marker
                                        mCurrent = mMap.addMarker(new MarkerOptions()
                                                .position(new LatLng(latitude,longtitude))
                                                .title("You"));

                                        radius= new LatLng(latitude,longtitude);
                                        mMap.addCircle(new CircleOptions()
                                                .center(radius)
                                                .radius(1000) // in Metters
                                                .strokeColor(Color.BLUE)
                                                .fillColor(0x220000FF)
                                                .strokeWidth(5.0f)
                                        );

【问题讨论】:

    标签: android geolocation location


    【解决方案1】:

    您的geoFire.setLocation 使用“您”键保存了您的位置。 如果您显示您的数据库结构会很好。 但是要在某个半径范围内保存位置,您需要这样做:

        GeoFire geoFire = new GeoFire(FirebaseDatabase.getInstance().getReference().child(GEOFIRE_PATH));
                GeoQuery geoQuery = geoFire
                        .queryAtLocation(new GeoLocation(myLocation.latitude, myLocation.longitude), RADIUS);
    
                geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() {
                    ...onData methods
                }
    

    【讨论】:

    • 我知道了,但在那之后,我如何比较/计算 mylocation 与数据库中的位置?谢谢
    • 为什么需要“比较/计算”?它会自动提供您在.queryAtLocation() 第二个参数中输入的半径范围内的位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多