java - setLocation 的 Geofire 错误

标签 java android firebase firebase-realtime-database geofire

我正在尝试学习 geofire 我尝试实现 SFVehicle 应用程序,但它显示错误,你能帮忙吗这是我项目的关键部分

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private static final GeoLocation INITIAL_CENTER = new GeoLocation(37.7789, -122.4017);
    private static final int INITIAL_ZOOM_LEVEL = 14;
    private static String GEO_FIRE_DB = "https://learngoef.firebaseio.com";
    private static String GEO_FIRE_REF = GEO_FIRE_DB+ "/_geofire";



    private Circle searchCircle;
    private GeoFire geoFire;
    private GeoQuery mGeoQuery;

    private Map<String,Marker> markers;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);


        FirebaseDatabase database = FirebaseDatabase.getInstance();
        geoFire = new GeoFire(database.getReference().child("geofire_location"));

        String key = geoFire.getDatabaseReference().push().getKey();
        geoFire.setLocation(key,new GeoLocation(37.7789, -122.4017));




    }

这是我遇到的错误:

java.lang.NoSuchMethodError: No virtual method setValue(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; in class Lcom/google/firebase/database/DatabaseReference; or its super classes (declaration of 'com.google.firebase.database.DatabaseReference' appears in /data/app/com.myapps.learninggeofire-2/split_lib_dependencies_apk.apk)

最佳答案

如果你在它的参数中添加一个监听器就可以正常工作。作为

 geoFire = new GeoFire(database.getReference().child("geofire_location"));

 String key = geoFire.getDatabaseReference().push().getKey();
 geoFire.setLocation(key,new GeoLocation(37.7789, -122.4017)),new 
 GeoFire.CompletionListener(){
            @Override
            public void onComplete(String key, DatabaseError error) {
                //Do some stuff if you want to
            }
        });

我想这可能对你有帮助。

关于java - setLocation 的 Geofire 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48930447/

相关文章:

安卓电池使用情况

javascript - 如何在 Android 中远程更新我的 cordova/phonegap 移动应用程序?

android - 数据消息与通知消息,(可折叠和不可折叠混淆)

javascript - Firebase javascript 身份验证 - 错误 : "Uncaught ReferenceError: firebase is not defined"

java - 如何通过只读操作最优地遍历 Neo4j Graph?

java - SPRING|Java - 在查询中使用带有 SpEl 的 IN 子句

java - Android 覆盖 PointF 以获得接近 java Point2D.double 的东西

firebase - Firebase Auth 中哪些被视为 API 限制

java - 如何使字符串索引从 1 开始

JavaFx 8 双向绑定(bind)