java - 当标记 android studio 触发时,如何获取我保存在 firebase 中的数据 latlng

标签 java android google-maps firebase firebase-realtime-database

我在 firebase 中有 2 个数据,即纬度经度。

示例:

数据 qwe0912830qwiejkasd 纬度 : 12345 经度 : 23412 qweoksldfmkl2091kmw 纬度:23423 经度:09801

我在 map 上有 2 个标记,标记位置基于 Firebase 中的数据,我需要的是,当我单击 2 个标记中的 1 个时,它会显示用 Toast 编写的纬度和经度。

这就是我所做的,但是当我单击标记时它崩溃了。

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                tujuan.setText(marker.getTitle());
                LatLng markerLocation = marker.getPosition();
                //Toast.makeText(MapsActivity.this, markerLocation+"", Toast.LENGTH_SHORT).show();               FirebaseDatabase.getInstance().getReference().child("Pariwisata").addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                            for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
                                double latt = (double) snapshot.child("Latitude").getValue(Double.class);
                                double longg = (double) snapshot.child("Longitude").getValue(Double.class);
                                Toast.makeText(MapsActivity.this,latt+", "+longg, Toast.LENGTH_SHORT).show();
                            }
                    }
                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                    }
                });

                return false;

            }
        });

最佳答案

试试这个:

FirebaseDatabase.getInstance().getReference().child("Data").addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
     for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
        double latt = (double) snapshot.child("latitude").getValue();
        double longg = (double) snapshot.child("longitude").getValue();

     }
}

关于java - 当标记 android studio 触发时,如何获取我保存在 firebase 中的数据 latlng,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49668260/

相关文章:

java - 在 App Engine 上托管应用程序服务器?

java - onActivityResult() 和 : failure delivering result resultinfo who=null request=1 result=-1 data=intent (has extras)

java - 使用 JDK5 进行跟踪

java.lang.ClassNotFoundException 即使我为类文件指定 -cp 参数

android - android studio IDE中的Kotlin编译器预发布问题

java - 如何在 Android 中清除 HttpURLConnection 的缓存?

java - map 中的多个标记未通过 SupportMapFragment 显示

javascript - 谷歌地图 API : multiple direction/route on same map

Android 谷歌地图去当前位置没有动画

java - 我使用Spring+MongoDB,当我执行查询方法时,它抛出java.lang.ClassNotFoundException : com. mongodb.MongoException$DuplicateKey