当前活动页面接受先前活动的用户ID,并搜索相应的用户并在地图上标记其位置。
没有编译错误。每当我在移动设备上访问此活动时,应用程序就会崩溃。
public class map extends FragmentActivity implements OnMapReadyCallback {
private String UserID;
private GoogleMap mMap;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private studetails stu;
//private LocationListener Locationlistener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
UserID = getIntent().getExtras().getString("UserId");
DocumentReference doc = db.collection("Userdetails").document(UserID);
doc.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
stu = documentSnapshot.toObject(studetails.class);
}
});
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//ActivityCompat.requestPermissions( activity: this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PackageManager.PERMISSION_GRANTED);
//ActivityCompat.requestPermissions( activity: this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PackageManager.PERMISSION_GRANTED);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
Location loc;
loc = stu.getlocation();
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(loc.getLatitude(), loc.getLongitude());
mMap.addMarker(new MarkerOptions().position(sydney).title("Busstop"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Custom Object used to push data into firestore
我是android-studio的新手,如果错过任何相关信息,请在下面提及。
答案 0 :(得分:0)
根据您的日志FirebaseApp is not initialized in this process
。我怀疑这是您的问题所在的行:
FirebaseFirestore db = FirebaseFirestore.getInstance();
与创建类实例一样,即使未正确设置FirebaseApp,它也会自动尝试获取默认的Firestore实例。
请不要在声明中初始化db
,而应遵循onCreate
,特别是在您致电FirebaseApp.initializeApp(this)