How to convert latitude longitude into CLLocationCoordinate2D
Asked Answered
L

4

10

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?

Lucubrate answered 22/7, 2011 at 12:37 Comment(1)
Your code looks fine. Try to cast the expression to CLLocationCoordinate2D. See if my answer below helps you!Travancore
C
25

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

Chuckle answered 22/7, 2011 at 12:40 Comment(0)
O
7

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;
Outlast answered 22/7, 2011 at 12:43 Comment(0)
T
6

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.

Travancore answered 22/7, 2011 at 12:51 Comment(0)
D
1

Update > Swift 4

let loc_coords = CLLocationCoordinate2DMake(47.601089,-52.740439)

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

Thanks

Dipterocarpaceous answered 16/5, 2018 at 10:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.