如何接收Firebase存储的经纬度数据并将其放入标记中 [英] How to receive latitude and longitude data stored from Firebase and put it in a marker
问题描述
我使用firebase和Google地图制作应用程序
但是我正在实现这个功能:
在AddActivity活动中,设置纬度和经度通过点击地图的某个部分放置一个标记
当你按下发送按钮这些数据被发送到firebase
而我想要拯救作为标题发送的那个标记的数据,
并且它被放置在FireBase的经度和纬度的MainActivity的地图中
这是我的数据库是如何组织的
我需要获取数据库的坐标,并用这些坐标将一个标记放置在确切的地方
相关的代码:
发送信息的addActivity方法
private v oid sendPostEvent(){
FirebaseUtils.getUserRef(FirebaseUtils.getCurrentUser()。getEmail().export(。,,))。addListenerForSingleValueEvent(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
User user = dataSnapshot.getValue(User.class);
final String postuid = FirebaseUtils.getUid();
字符串organizadoPor = etOrganizadoPor.getText()。toString();
字符串tituloEvento = etTituloEvento.getText()。toString();
String descripcionEvento = etDescripcion.getText()。toString();
字符串costoEvento = etCosto.getText()。toString();
mPost.setOrganizadoPor(organizadoPor);
mPost.setMes(mPost.getMes());
mPost.setDia(mPost.getDia());
mPost.setHora(mPost.getHora());
mPost.setMinutos(mPost.getMinutos());
mPost.setTitulo(tituloEvento);
mPost.setDescripicion(descripcionEvento);
mPost.setCosto(costoEvento);
mPost.setLatitud(mPost.getLatitud());
mPost.setLongitud(mPost.getLongitud());
$ b $ / code>
MainActivity方法:
sendMethod使用我需要在MainActivity地图中放置一个标记
@Override
public void onMapReady(GoogleMap googleMap){
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
UiSettings uiSettings = mMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED&& ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager .PERMISSION_GRANTED){
TastyToast.makeText(NavActivity.this,GPS权限未启用,TastyToast.LENGTH_LONG,TastyToast.ERROR).show();
return;
}
mMap.setMyLocationEnabled(true);
$ b}
我的数据库方法: I'm making an app with firebase and google maps
But I'm implementing this: In the AddActivity activity, you set the latitude and longitude by clicking on a certain part of the map by placing a marker
When you press the "send" button these data are sent to the firebase And I would like to rescue the data of that marker that was sent as the title,
And that it is placed in the map of the MainActivity with the latitude and longitude that is in the firebase This is how my database is organized I need to get the coordinates of the database, and with those coordinates a marker is placed in the exact place the relevant code: the addActivity method that send the information the MainActivity method:
when the sendMethod is used i need to put a marker in the MainActivity map my database methods:
这篇关于如何接收Firebase存储的经纬度数据并将其放入标记中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ $ p $ // POST参考
public static DatabaseReference getPostRef(){
返回FirebaseDatabase。 getInstance()
.getReference(Pk);
public static Query getPostQuery(){
return getPostRef()。orderByChild(Tc);
public static DatabaseReference getMyPostRef(){
return FirebaseDatabase.getInstance()。getReference(Mp)
.child(getCurrentUser()。getEmail()。replace 。,,));
$ / code>
Firebase locationRef = mRootRef.child(您的参考);
locationRef.addValueEventListener(new com.firebase.client.ValueEventListener(){
@Override
public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot){
$ b $ (DataSnapshot snapm:dataSnapshot.getChildren()){
双纬度= snapm.child(latitud)。getValue(Double.class);
双经度= snapm.child(longitudinal).getValue(Double.class);
}
}
@Override
public void onCancelled(FirebaseError firebaseError){
throw firebaseError.toException();
}
});
private void sendPostEvent(){
FirebaseUtils.getUserRef(FirebaseUtils.getCurrentUser().getEmail().replace(".",",")).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
final String postuid = FirebaseUtils.getUid();
String organizadoPor = etOrganizadoPor.getText().toString();
String tituloEvento = etTituloEvento.getText().toString();
String descripcionEvento = etDescripcion.getText().toString();
String costoEvento = etCosto.getText().toString();
mPost.setOrganizadoPor(organizadoPor);
mPost.setMes(mPost.getMes());
mPost.setDia(mPost.getDia());
mPost.setHora(mPost.getHora());
mPost.setMinutos(mPost.getMinutos());
mPost.setTitulo(tituloEvento);
mPost.setDescripicion(descripcionEvento);
mPost.setCosto(costoEvento);
mPost.setLatitud(mPost.getLatitud());
mPost.setLongitud(mPost.getLongitud());
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
UiSettings uiSettings = mMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
TastyToast.makeText(NavActivity.this, "GPS permission are not enabled", TastyToast.LENGTH_LONG, TastyToast.ERROR).show();
return;
}
mMap.setMyLocationEnabled(true);
}
// POST REFERENCE
public static DatabaseReference getPostRef() {
return FirebaseDatabase.getInstance()
.getReference("Pk");
}
public static Query getPostQuery() {
return getPostRef().orderByChild("Tc");
}
public static DatabaseReference getMyPostRef() {
return FirebaseDatabase.getInstance().getReference("Mp")
.child(getCurrentUser().getEmail().replace(".", ","));
}
Firebase locationRef = mRootRef.child("your reference");
locationRef.addValueEventListener(new com.firebase.client.ValueEventListener() {
@Override
public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) {
for (DataSnapshot snapm: dataSnapshot.getChildren()) {
Double latitude = snapm.child("latitud").getValue(Double.class);
Double longitude = snapm.child("longitud").getValue(Double.class);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
throw firebaseError.toException();
}
});