1

I tried to store CLLocationCoordinate2D to NSMutableArray but I could only do it using NSValue. I want to get those coordinates stored in NSMutableArray in NSValue type as CLLocationCoordinate2D. How can I do that? I am having trouble getting those coordinates since it only pointers.

I tried to store using

[valueArray addObject:[CLLocationCoordinate2DMake(54.860812, -78.990710) ]]

it gives expected identifier error but I was successfully able to store using NSValue but I am not able to get the CLLocationCoordinate2D out of NSValue.

[valueArray addObject:[NSValue valueWithMKCoordinate:CLLocationCoordinate2DMake(54.860717, -78.990722)]]; 
for (NSValue *object in valueArray)
{   
    NSLog(@"%@", object]
    //return pointers
}

I will appreciate if somebody can help me on this and suggest me which is a better approach of storing CLLocation in a mutable array.

Argus
  • 2,241
  • 1
  • 22
  • 27
Rosh
  • 169
  • 16
  • 1
    This got marked as a duplicate, but that question doesn't seem to answer your question so I'll add that to get the coordinate back out the `NSValue` you want to use `object.MKCoordinateValue` – dan Apr 22 '15 at 18:07
  • Thanks dan. Worked perfectly – Rosh Apr 22 '15 at 18:26
  • http://stackoverflow.com/a/14708590/467105, http://stackoverflow.com/questions/14328173/how-to-store-cllocationcoordinate2d, http://stackoverflow.com/questions/24926718/sending-cllocationcoordinate2d-to-parameter-of-incompatible-type-my-code-in-xcod, etc. And there's always [the documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSValue_Class/index.html#//apple_ref/occ/clm/NSValue/valueWithMKCoordinate:). The "See Also" for valueWithMKCoordinate: lists MKCoordinateValue. –  Apr 22 '15 at 20:21
  • #import NSValue *coordinateValue; CLLocationCoordinate2D coordinate = [coordinateValue MKCoordinateValue]; – Argus Jun 01 '18 at 18:01
  • This is not duplicate. – Argus Sep 26 '18 at 10:55

0 Answers0