Search code examples
iphoneioscore-locationcllocation

Assigning lat long to CLLocation giving error not accepting any format


I am giving lat long to CLLocation in this way.

CLLocation *loc = [[CLLocation alloc]init];
    loc.coordinate.latitude = [sLat floatValue];
    loc.coordinate.longitude = [sLng floatValue];

Coming from

 NSMutableDictionary *locat = [dictLoc valueForKey:@"location"];
sLat = [locat valueForKey:@"lat"];
sLng = [locat valueForKey:@"lng"];

Showing correct values in console, but kills when allocated to cllocation. Please guide for the above. Thanks.


Solution

  • you can get the value in CLLocationCoordinate2D object like bellow...

    CLLocationCoordinate2D location;
    location.latitude = [sLat doubleValue];
    location.longitude = [sLng doubleValue];
    

    OR Also try to retain that string like bellow..

    sLat = [locat valueForKey:@"lat"];
    [sLat retain];
    sLng = [locat valueForKey:@"lng"];
    [sLng retain];
    

    and then assign it to CLLocation

    hope this helpful to you....