[Solved] To store gps location in firebase real time database


You can send the location to Firebase by using the Firebase Database and DatabaseReference classes. First you have to make sure that you have these SDK’s in build.gradle:

implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.4'

Also, make sure that you have set up your Realtime Database in the Firebase Console. It would be best if you choose the Testing option so that anybody can write to the database. If you have never used Firebase before, check out this documentation by Firebase to setup Firebase in your Android app.

Once you have added the code in your dependencies, do the following:

FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference databaseReference = firebaseDatabase.getReference("Locations"); 
//Instead of "Locations" you can say something else. Locations will be the name of your path where the location is stored.
//Create a Hashmap to store the information with a key and a value:
Hashmap<String, String> values = new Hashmap<>();
values.put("Location", city);
databaseReference.push().setValue(values);

You can add an onSuccessListener or onFailureListener to see if it worked.
If that didn’t work, check out this doc by Firebase.

0

solved To store gps location in firebase real time database