使用setLocation时出现Geofire错误

时间:2018-02-22 14:54:00

标签: 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:没有虚方法   的setValue(Ljava /郎/对象; Ljava /郎/对象;)LCOM /谷歌/火力/任务/任务;   在Lcom / google / firebase / database / DatabaseReference中;或者它的超级   课程(宣言)   &#39; com.google.firebase.database.DatabaseReference&#39;出现在   /data/app/com.myapps.learninggeofire-2/split_lib_dependencies_apk.apk)

4 个答案:

答案 0 :(得分:8)

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

 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
            }
        });

我认为它可能对你有所帮助。

答案 1 :(得分:0)

我花了4个小时来解决该错误

 geoFire.setLocation(userId, new GeoLocation(37.7789, -122.4017)),new 
 GeoFire.CompletionListener(){
            @Override
            public void onComplete(String key, DatabaseError error) {
                Log.e(TAG, "GeoFire Complete");
            }
        });

直到我将Firebase依赖关系更改为16.0.4而不是16.0.1之前,它仍然无法工作

答案 2 :(得分:0)

将您的geofire依赖项从最新版本降级到

实现'com.firebase:geofire-android:2.1.1'

答案 3 :(得分:0)

阅读本-https://github.com/firebase/geofire-java 它的支持-实现'com.firebase:geofire-java:3.0.0'(版本)

// ---------------------------------------- code ---- ---------------------------------------

firebaseAuth = FirebaseAuth.getInstance();
firebaseDatabase = FirebaseDatabase.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();


String userid = firebaseUser.getUid();
DatabaseReference ref = firebaseDatabase.getReference("Active Users");
GeoFire geoFire = new GeoFire(ref);


geoFire.setLocation(userid, new GeoLocation(location.getLatitude(), location.getLongitude()), new GeoFire.CompletionListener() {
    @Override
    public void onComplete(String key, DatabaseError error) {
        if (error!=null)
        {
            Toast.makeText(client_dashboard.this,"Can't go Active",Toast.LENGTH_SHORT).show();
        }
        Toast.makeText(client_dashboard.this,"You are Active",Toast.LENGTH_SHORT).show();
    }
});