使用setLocation时出现Geofire错误

rah*_*ani 5 java android firebase geofire firebase-realtime-database

我正在尝试学习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));




    }
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

java.lang.NoSuchMethodError:没有虚方法setValue(Ljava/lang/Object; Ljava/lang/Object;)Lcom/google/firebase/tasks/Task; 在Lcom/google/firebase/database/DatabaseReference中; 或其超级类('com.google.firebase.database.DatabaseReference'的声明出现在/data/app/com.myapps.learninggeofire-2/split_lib_dependencies_apk.apk)

小智 9

如果在其参数中添加侦听器,它将正常工作

 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
            }
        });
Run Code Online (Sandbox Code Playgroud)

我想这可能会对你有所帮助.