我已经在firebase中使用geofire插入了位置 [英] I have inserted location using geofire in firebase
问题描述
我已经在firebase中使用geofire插入位置,现在我想用标记检索单个Google地图活动中的所有位置。
我已经创建了地图活动,但我不知道如何从firebase中检索位置。
请帮我解决这个问题。使用一些源代码。
这是我的代码发送位置firebase
GeoFire geoFire = new
GeoFire(databaseReference.child(Location)。child(user.getUid()));
geoFire.setLocation(location,new
GeoLocation(location.getLatitude(),location.getLongitude()),new
GeoFire.CompletionListener(){
@Override
public void onComplete(String key,DatabaseError error){
if(error!= null){
Toast.makeText(gpdfuel.this,有一个错误
保存位置to GeoFire:+ error,Toast.LENGTH_LONG).show();
} else {
Toast.makeText(gpdfuel.this,保存在服务器上的位置
成功! LENGTH_LONG).show();
}
}
});
您必须首先创建数据引用
DatabaseReference ref = FirebaseDatabase.getInstance()。getReference(/ path /);
比geofire object
GeoFire geoFire =新GeoFire(ref);
现在可以在特定范围内检索地理位置
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat,long),radius);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener(){
@Override $ b $ public void onKeyEntered(String key,GeoLocation location){
Log.d(Const.TAG,String.format( Key%s在[%f,%f],key,location.latitude,location.longitude)中输入了搜索区域);
}
@Override
public void onKeyExited(String key){
Log.d(Const.TAG,String.format(Key%s is no in the search area,key));
}
@Override
public void onKeyMoved(String key,GeoLocation location){
Log.d(Const.TAG,String.format(Key%s within search within to [%f, ());
}
@Override
public void onGeoQueryReady(){
Log.d( Const.TAG,所有的初始数据已经被加载,事件已经被触发!);
}
@Override
public void onGeoQueryError(DatabaseError error){
Log.d(Const.TAG,这个查询有错误:+ error);
}
});
I have inserted location using geofire in firebase from one of the activity in android studio now I want to retrieve all the location in single google map activity with marker. I have created map activity, but I don't know how to retrieve the location from the firebase .
Please help I am stuck in this. With some source code.
Here is my code for sending location to firebase
GeoFire geoFire = new
GeoFire(databaseReference.child("Location").child(user.getUid()));
geoFire.setLocation("location", new
GeoLocation(location.getLatitude(), location.getLongitude()), new
GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
if (error != null) {
Toast.makeText(gpdfuel.this, "There was an error
saving the location to GeoFire: " + error, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(gpdfuel.this, "Location saved on server
successfully!", Toast.LENGTH_LONG).show();
}
}
});
you have to create a data reference first
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/path/");
than geofire object
GeoFire geoFire = new GeoFire(ref);
now retreive geo firelocation within particular range like this
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(lat, long), radius);
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Log.d(Const.TAG,String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude));
}
@Override
public void onKeyExited(String key) {
Log.d(Const.TAG,String.format("Key %s is no longer in the search area", key));
}
@Override
public void onKeyMoved(String key, GeoLocation location) {
Log.d(Const.TAG,String.format("Key %s moved within the search area to [%f,%f]", key, location.latitude, location.longitude));
}
@Override
public void onGeoQueryReady() {
Log.d(Const.TAG,"All initial data has been loaded and events have been fired!");
}
@Override
public void onGeoQueryError(DatabaseError error) {
Log.d(Const.TAG,"There was an error with this query: " + error);
}
});
这篇关于我已经在firebase中使用geofire插入了位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!