【发布时间】:2018-03-03 06:23:25
【问题描述】:
我有这个基于位置跟踪的项目。这包括两个移动应用程序,其中一个应用程序将 GPS 坐标推送到 firebase。和其他应用程序检索坐标。当我检索坐标并将它们设置为纬度和对数时,应用程序崩溃而没有任何异常或错误。我在这里做错了什么?我这样做对吗?
以下是我的代码...
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
DatabaseReference myRef;
final Double[] latitu = {7.02343187};
final Double[] longitu = {79.89658312};
myRef = FirebaseDatabase.getInstance().getReference("appontrain").child("location");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
latitu[0] = (Double) dataSnapshot.child("lat").getValue();
longitu[0] = (Double) dataSnapshot.child("lon").getValue();
Log.d("LatLon", latitu[0] + longitu[0] +"");
Toast.makeText(LiveTrain.this, latitu[0].toString()+" - "+ longitu[0].toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w("Exception FB",databaseError.toException());
}
});
LatLng trainLocation = new LatLng(latitu[0], longitu[0]);
mop = new MarkerOptions();
mop.position(trainLocation);
mop.title("Train: Muthu Kumari");
mop.icon(icon);
mMap.addMarker(mop);
mMap.moveCamera(CameraUpdateFactory.newLatLng(trainLocation));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(trainLocation,13f));
}
当我将纬度和经度硬编码到 LatLng 对象时,标记在应用程序上显示,没有任何错误。当我从 firebase 设置值时,它会崩溃。请帮我!
下面是logcat
09-22 00:40:41.731 2711-2744/com.smartraveller.srt D/FA: Logging event (FE): app_exception(_ae), Bundle[{firebase_event_origin(_o)=crash, firebase_screen_class(_sc)=LiveTrain, firebase_screen_id(_si)=4621265793058976305, timestamp=1506021041714, fatal=1}]
09-22 00:40:41.831 5050-2755/? V/FA-SVC: Logging event: origin=crash,name=app_exception(_ae),params=Bundle[{firebase_event_origin(_o)=crash, firebase_screen_class(_sc)=LiveTrain, firebase_screen_id(_si)=4621265793058976305, timestamp=1506021041714, fatal=1}]
09-22 00:40:41.841 5050-2755/? V/FA-SVC: Saving event, name, data size: app_exception(_ae), 86
09-22 00:40:41.841 5050-2755/? V/FA-SVC: Event recorded: Event{appId='com.smartraveller.srt', name='app_exception(_ae)', params=Bundle[{firebase_event_origin(_o)=crash, firebase_screen_class(_sc)=LiveTrain, firebase_screen_id(_si)=4621265793058976305, timestamp=1506021041714, fatal=1}]}
以下是数据库层次结构。
【问题讨论】:
-
分享你的数据库图片
-
@MalikAhsan 我用数据库图片编辑了问题。
-
很难相信 logcat 中没有异常的堆栈跟踪。如果您在 Android Studio 中查看 logcat,请确保您没有设置过滤器。
标签: android google-maps firebase firebase-realtime-database geolocation