If you are using these coordinates for a pathing purposes (coordinates in a path), string-encoding the array could be a really good way to go. This might be too complicated to implement yourself, but I suggest taking a look at Google's Encoded Polylines.
The idea there is that you have an array of coordinates (lat/long), and it converts the entire array to one single string.
If by any chance you are using GoogleMaps
in your project, that would be the easiest, by far. Let's say you create a GMSPath
-object like this:
let path = GMSMutablePath()
path.add(CLLocationCoordinate2D)
path.add(CLLocationCoordinate2D)
path.add(CLLocationCoordinate2D)
Then simply do path.encodedPath()
to get a string representation of the path.
In their example, these points: (38.5, -120.2), (40.7, -120.95), (43.252, -126.453)
are turned into this single string:
_p~iF~ps|U_ulLnnqC_mqNvxq`@
If you store this string in your database, and want to extract them again, you can simply say
let path = GMSPath(fromEncodedPath: encodedString)
This is really good for storing in DB, or sending over API.
Then again, it might not be fit for your use.