String to CLLocation latitude and Longitude

泄露秘密 提交于 2019-12-02 17:36:33

I think you need to:

LocationAtual.coordinate.latitude = [@"-56.6462520" floatValue];
LocationAtual.coordinate.longitude = [@"-36.6462520" floatValue];

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];

Swift Answer for the lazy:

var LocationAtual: CLLocation = CLLocation(latitude: -56.6462520, longitude: -36.6462520)

CLLocation coordinate is actually a read only value

    @property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

So the best way to assign dummy data to coordinates is AMITp way

lattitude and longitude are double values so need to be assigned this way.

CLLocation *LocationAtual=[[CLLocation alloc] initWithLatitude:[[location objectForKey:@"latitude"] doubleValue] longitude:[[location objectForKey:@"longitude"] doubleValue]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!