Search code examples
objective-ccoordinatescllocation

Saving coordinates into a string


tearing my hair out here I need to put the values of into an array as a string someone on here advised me to set up like this...

[twitterLocation addObject:[NSString stringWithFormat:@"%g,%g", latitude, longitude]];

However this is not working. The latitude, longitude contain values in my log but will not combine into the string and the array - IT GET RETURNED AS NULL. MY latitude, longitude are set as DOUBLES Thanks


Solution

  • Form reading the comments I guess you need to at least allocate your array:

    double lat = 0.3231231;
    double lon = 0.4343242;
    NSMutableArray *twitterLocation = [[NSMutableArray alloc]init];
    [twitterLocation addObject:[NSString stringWithFormat:@"%g%g", lat, lon]];
    

    If you skip the allocation the mutable array has no memory location to hold objects.