Save a CLLocationCooridnate2D array in Firestore

别来无恙 提交于 2019-12-02 13:29:30

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!