使用setLocation时出现Geofire错误

问题描述 投票:4回答:3

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

java android firebase firebase-realtime-database geofire
3个回答
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
            }
        });

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


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之前,它仍然无法工作


0
投票

将您的地理位置依赖关系从最新版本降级为

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

© www.soinside.com 2019 - 2024. All rights reserved.