1

These both seem like common options that are used to store an array of coordinates. If I were to store 1000 coordinates in an array, would it be better to use an array of CGPoint or CLLocation?

CLLocation seems to store extra information like altitude and timestamp. If I only care about the latitude and longitude, would it be a better idea to store coordinates as CGPoint? I am guessing storing extra unneeded info like altitude and timestamp would mean CLLocation has a larger memory footprint?

On the other hand, I am using the coordinates to eventually create annotations and place them on a map. The annotation is created using CLLocationCoordinate2D.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3614030
  • 481
  • 6
  • 16
  • You provided your own answer in the very last sentence of your question. – rmaddy Jul 29 '18 at 22:41
  • Thank you. I am a bit curious what the size of a CGPoint object and CLLocation object is? Does CLLocation take up a lot more memory? – user3614030 Jul 29 '18 at 22:45
  • Just a guess, but since `CLLocation` contains longitude, latitude, along with altitude, and "values indicating the accuracy of those measurements. But why the concern? SO you wish to place 1000 coordinates on a map on a device with gigabytes or memory. I'd guess your *first* concern is having those 1000 coordinates appear as specific places in a single screen. On a 4 inch iPhone SE you really can't do that. At which point you need to *cache* the coordinates like cells in a tableview, maybe by storing them in a quickly retrievable database? Either way, good luck! –  Jul 29 '18 at 23:02
  • A CLLocation will take up more memory since it has more properties. But you won't be using either since you will only be using `CLLocationCoordinate2D`. – rmaddy Jul 29 '18 at 23:03
  • 1
    A `CGPoint` is not suitable for saving geographic coordinates. `CGPoint` values store an X and a Y value as `CGFloat` values, which are 4-byte values. The values in a `CLLocationCoordinate2D` are `Double`s, which are 8-byte values with a lot more precision. If you don't want to save an array of `CLLocation` objects, use an array of `CLLocationCoordinate2D`s instead. – Duncan C Jul 29 '18 at 23:58

0 Answers0