How can I write array of coordinates to Cloud Firestore

前端 未结 2 688
滥情空心
滥情空心 2021-01-24 19:05

How can I write an array of coordinates to the Cloud Firestore as a GeoPoint datatype?

I do have an arraylist points with coordin

相关标签:
2条回答
  • 2021-01-24 19:11

    When passing FieldValue.arrayUnion as the second argument to the update() method like in the the following line of code:

    docRef.update("Test", FieldValue.arrayUnion(points));
    

    It means that you are telling Firebase that you want to update a property within a document which is of type array with a List, which is actually not possible, hence this error:

    Nested arrays not supported
    

    If you have documents that contain nested arrays, please note that a regular update is currently not possible. What can you do instead is to get the entire document and call getData() on the DocumentSnapshot object. The type of object that is returned is a Map<String, Object>. Iterate through the map, update the desired value and write the document back in the database.

    0 讨论(0)
  • 2021-01-24 19:21

    You can write your coordinates in cloud firestore like this

        Map<String, Object> map = new HashMap<>();
         map.put("coordinates", Arrays.asList(points));
    
         db.collection("REFERENCE").document("mDocumentId")
                .update(map);
    
    0 讨论(0)
提交回复
热议问题