Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String to CLLocation latitude and Longitude

Tags:

I have two strings representing latitude and longitude like: "-56.6462520", and i want to assign then to a CLLocation object to compare to my current location.I tried the following code but i get errors only:

CLLocation * LocationAtual = [[CLLocation alloc]init];
LocationAtual.coordinate.latitude = @"-56.6462520";
LocationAtual.coordinate.longitude = @"-36.6462520";

and then compare the object with my actual location latitude and longitude. Any suggestions?

like image 522
Vinicius Albino Avatar asked Oct 26 '11 19:10

Vinicius Albino


1 Answers

You cannot assign directly into coordinate - it is a readonly property of CLLocation.
Use the following instance method:

- (instancetype)initWithLatitude:(CLLocationDegrees)latitude
                       longitude:(CLLocationDegrees)longitude

example:

CLLocation *LocationAtual = [[CLLocation alloc] initWithLatitude:-56.6462520 longitude:-36.6462520];
like image 155
AmitP Avatar answered Sep 19 '22 15:09

AmitP