Save a CLLocationCooridnate2D array in Firestore

前端 未结 1 933
误落风尘
误落风尘 2021-01-29 06:22

I\'m trying to save a CLLocationCoordinate2Darray into Firestore, but I\'m getting error:

\'FIRInvalidArgumentException\', reason: \'Unsupp

相关标签:
1条回答
  • 2021-01-29 06:41

    To break it down, Firebase doesn't know what a CLLocationCoordinate2D object is. But it does know what an array is, and it does know what strings and integers and doubles are. So you will have to parse your array of locations into something it can understand. You can store the value in Firestore since a coordinate is really just a pair of double values. You can do this a number of ways, but the easiest is to probably split the locations array, one for the latitude values and one for longitude. For example, you can use let latitudes = locations.map({ $0.latitude }) and the same for longitudes. Then in Firestore, you would update it to something like:

                     "Person": txtfield_person.text!,
                     "What": txtfield_what.text!,
                     "Date": txtfield_Datum.text!,
                     "Time": txtfield_Time.text!,
                     "Timer": txtfield_timer.text!,
                     "Kilometers": txtfield_km.text!,
                     "LocationLatitudes": latitudes,
                     "LocationLongitudes": longitude,
                    ]
    

    Apply reverse logic for retrieving. You will need to iterate over the lat & long arrays and combine into a single array of CLLocationCoordinate2D objects.

    0 讨论(0)
提交回复
热议问题