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

3
  • 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 stackoverflow.com/questions/42410174/… and stackoverflow.com/questions/41045025/… Commented Apr 30, 2017 at 21:04
  • What should I do then exactly?@FrankvanPuffelen Commented Apr 30, 2017 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. Commented Apr 30, 2017 at 21:38

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.