开发者

How to convert latitude longitude into CLLocationCoordinate2D

开发者 https://www.devze.com 2023-03-22 10:28 出处:网络
I want to convert lat lon to CLLocationCoordinate2D. self.currentLocation = {.latitude = 0.0, .longitude = 0.0};

I want to convert lat lon to CLLocationCoordinate2D.

self.currentLocation = {.latitude = 0.0, .longitude = 0.0};

This gives me error "Expected expression".

What am I doing wrong开发者_开发知识库?


Use CLLocationCoordinate2DMake(CLLocationDegrees latitude, CLLocationDegrees longitude) to create the coordinates.


While you could use CLLocationCoordinate2DMake you have to pay attention because it is available in iOS 4.0 and later only. You can try this to make it 'manually':

CLLocationCoordinate coordinate;
coordinate.latitude = 0.0;
coordinate.longitude = 0.0;

self.currentLocation = coordinate;


Your code seems to be correct. That should not throw any errors/warnings. Make sure self.currentLocation is a CLLocationCoordinate2D. Try to cast the expression like below,

self.currentLocation = (CLLocationCoordinate2D){.latitude = 0.0, .longitude = 0.0};

Alternatively you can also use CLLocationCoordinate2DMake method.


Update > Swift 4

let loc_coords = CLLocationCoordinate2DMake(47.601089,-52.740439)

For more details please have a look to apple developer website: CLLocationCoordinate2DMake

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消