0

I am able to read and retrieve String, double, custom objects from firebase database but am not able to read Location object specifically.

How do I read Location object from firebase database?

FirebaseDatabase snapshot

I want to read the data in the location field from the database. I have already written into the database

KENdi
  • 7,576
  • 2
  • 16
  • 31
  • The Firebase Database client can only serialize simple types (as you said) and POJO classes that consists of simple types and getters and setters. Most built-in Android classes don't adhere to these rules, so cannot directly be written to/read from the database. See http://stackoverflow.com/questions/42410174/firebase-database-error-found-conflicting-getters-for-name-isaccessibilityfoc/42418502#42418502 and http://stackoverflow.com/questions/41045025/android-save-object-in-firebase – Frank van Puffelen Apr 30 '17 at 21:04
  • What should I do then exactly?@FrankvanPuffelen – sahil jain Apr 30 '17 at 21:15
  • You will need to create you own Java class that contains just the information that you want to store in the database. If you're having problems with that, share the [minimal code that reproduces that problem](http://stackoverflow.com/help/mcve). – Frank van Puffelen Apr 30 '17 at 21:38

1 Answers1

0

To read complex objects from firebase, you need either to have a JSON parser to extract location information.
Another simple idea is to create a simple class encapsulating necessary location information with setters and gettors i.e. latitude and longitude.
Further simpler method is to add these attributes to the user class you are using to handle users data. I have used the latter approach to save location info in a project I am working on.

Maged Saeed
  • 1,784
  • 2
  • 16
  • 35