使用Android应用程序更新位置数据我正在开发一个简单的Android应用程序中,我需要创建就像尤伯杯地图和跟踪定位...我使用火力为我的数据库将存储用户的位置。 要存储我创建的时候我的MainActivity调用时调用的服务 位置我现在面临的问题是,该位置在数据库即当位置发生变化,也不会得到在数据库中更新得到更新一次我必须重新启动应用程序的新位置得到更新。在火力数据库
这里的onLocationChanged方法的代码在我的位置服务
public void onLocationChanged(Location location) {
Log.d("lam", "onLocationChanged:lam "+location.getLatitude()); //The log gets updated but not the values in database
Map<String,Object> taskMap=new HashMap<>();
taskMap.put("Latitude",location.getLatitude());
taskMap.put("Longitude",location.getLongitude());
try{
urlCurrenUser.updateChildren(taskMap);//urlCurrentUser is the path to database
}catch(Exception e){}
}
我也试过
public void onLocationChanged(Location location) {
Log.d("lam", "onLocationChanged:lam "+location.getLatitude()); //The log gets updated but not the values in database
try {
urlCurrenUser.child("Lattitude").setValue(location.getLattitude());
urlCurrenUser.child("Longitude").setValue(location.getLongitude());
}catch (Exception e){}
我呼吁在OnCreate()我的主要活动的服务
编辑 我认为这是我的urlCurrentUser(参考数据库)中的问题时,应用程序开始于第一次尝试的位置变得updat编辑在数据库中,但是当位置变化,并再次代码调用来更新新的坐标它提供了一个例外,即
显示java.lang.NullPointerException:试图调用虚拟方法 “com.firebase.client。火力地堡 com.firebase.client.Firebase.child(java.lang.String中)”空对象 参考
我只是不明白怎么解决这个 这里是我的数据库结构 的快照enter image description here
数据库参考代码
urlCurrenUser = new Firebase(URL).child("users").child(authData.getUid());