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