我有两个表示纬度和经度的字符串,例如:“-56.6462520”,然后我想将其分配给 CLLocation 对象以与我当前的位置进行比较。我尝试了以下代码,但仅出现错误:
CLLocation * LocationAtual = [[CLLocation alloc]init];
LocationAtual.coordinate.latitude = @"-56.6462520";
LocationAtual.coordinate.longitude = @"-36.6462520";
然后将物体与我实际所在位置的经纬度进行比较。有什么建议吗?
最佳答案
您不能直接分配给坐标 - 它是 CLLocation 的只读属性。
使用以下实例方法:
- (instancetype)initWithLatitude:(CLLocationDegrees)latitude
longitude:(CLLocationDegrees)longitude
例子:
CLLocation *LocationAtual = [[CLLocation alloc] initWithLatitude:-56.6462520 longitude:-36.6462520];
关于iphone - String to CLLocation经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7907734/