I have already seen the code to store a single point in firebase. But what I want to know is how to store whole polylines in firebase database? A decoded polyline is basiclly List. I want to know how to store many such type of lists in firebase so that I can retrieve later and perform operations on whole polyline.
Firebase use JSON format Database
Pass types that correspond to the available JSON types as follows:
String
Long
Double
Boolean
Map
List
you can pass any of data type a value in setValue() method and Lists and Map ,too.
Example:
Firebase ref = new Firebase("<my-firebase-app>/names"):
String[] names = {"John","Tim","Sam","Ben"};
List nameList = new ArrayList<String>(Arrays.asList(names));
// Now set value with new nameList
ref.setValue(nameList);
you can pass your custome object list,too.
Related
I want to create an array programmatically in firestore. Also, I want to update the array as shown in the image attached.
I want to store all reference Numbers in this array. And whenever there is a new reference number, I want to update the array. Please help.
This is what I have tried. I know it's wrong. It's not updating the array rather replacing it.
Map<String, Object> mapone= new HashMap<>();
Map<String, Object> maptwo = new HashMap<>();
mapone.put("Refnum", f_refrenceNum);
maptwo.put("RefNumber", mapone);
upiRefnum.set(maptwo,SetOptions.merge());
Your code is telling Firestore to the RefNumber.Refnum fields with the values you specify for is.
If you want to add f_refrenceNum to the array, you can use an array-union operation:
mapone.put("Refnum", FieldValue.arrayUnion(f_refrenceNum));
This will add f_refrenceNum if it isn't already in the array. If it is already in the array and you want to add a duplicate, you will have to read the document into your application code, add the number in your application code, and then write the entire array back to the database.
See the Firestore documentation on adding items to an array.
I have a schema like below in firestore:
I have document snapshot listener written to fetch the whole array via:
// inside snapshot listener
List<String> order_data= (List<String>) documentSnapshot.get("done"); // this returning whole array!
But i want only last element from the done array. Any help people?
If you want any data in a document, you have to read the entire document. There is no avoiding that.
If you already have the contents of a list field in a List object, then you can get the list item in that list using:
String last = order_data.get(order_data.size() - 1);
I wish to get an array from the Parse cloud. After tapping on an item in a list (which contains the ParseObject reference), the item will open a new activity and from this I want to get the array list stored in the latLngPoints key in Parse. I have googled and only found the following solution but it does not work:
ArrayList<ParseGeoPoint> parseList = (ArrayList<ParseGeoPoint>) getIntent().getExtras().getParcelableArrayList("latLngPoints");
Is it possible to even do it this way, or will I have to create a Parse object and create a request to get the information I need?
ParseObjects are not parcelable. You can pass an array list of longs that represent lat and long
I am a newbie with firebase and trying to use this as the backend for an android app to store data. The format of the data is a key,value pair.
This is the code that I am using to store the data :
Map<Integer, PersonData> map = new HashMap<Integer, PersonData>();
map.put(PersonData.getID(), new PersonData("abcd", 12345));
Firebase ref = new Firebase(url).push();
ref.setValue(map);
Due to the push reference being used the data is getting stored like this :
-J5upSABqTLJ1Wfu-jFq
12345
id: 12345
name: abcd
Where-as I want the data to be store like this :
12345
id: 12345
name: abcd
I am not entirely sure if the code sample above is the right way to store data. Since I want to be able to update the existing data at a later point in time . Any suggestions ?
EDIT 1: I am thinking I need to use push so that I don't over-write the existing data in the firebase repo.
I have just tried to get the data back using the getValue() method and I can only fetch data which is in MAP
EDIT 2: without using a push() method with my reference I can see that the any previous data is getting overwritten and only the latest information is available. I am wondering if they is a better way to obtain the reference and still maintain the previous information
So it looks like you have your own system of unique ids, in which case you shouldn't need to use the .push method (that is just a helper to get a unique ref for new data). So instead of push you should be able to do:
Map<Integer, PersonData> map = new HashMap<Integer, PersonData>();
map.put(PersonData.getID(), new PersonData("abcd", 12345));
Firebase ref = new Firebase(url).child("12345");
ref.setValue(map);
Assuming your id is "12345" and url is pointing at the location where you want to store all of your persons.
To update the data without overwriting, your ref would be:
Firebase ref = new Firebase(url).child("12345");
And instead of using .setValue you would want to use ref.updateChildren(updates). You can see how to structure the updates from the example in the docs:
Map<String, Object> updates = new HashMap<String, Object>();
updates.put("first", "Fred");
updates.put("last", "Swanson");
nameRef.updateChildren(updates);
I am trying to implement a data structure which allows me to keep track of an index (so I can blindly access the data points), a key (which needs to be there to identify the data in the rest of the program), and a value.
I've looked at a map, but that does not allow me to access the data points without any key. I need some combination of a Queue and a Map. Does this exist and I'm just missing it? Thanks for the help.
I believe what you are looking for is a LinkedHashMap. It will return an ordered collection and you can access values via a key.
LinkedHashMap<Key, Value> myMap = new LinkedHashMap<Key, Value>();
myMap.put(aKey, aValue); //adds to map.
myMap.values(); //returns collection of values
aValue = myMap.get(Key); //returns a value with the given key