Harsh
Harsh

Reputation: 666

How to convert latitude longitude into CLLocationCoordinate2D

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?

Upvotes: 10

Views: 17082

Answers (4)

Harjot Singh
Harjot Singh

Reputation: 6927

Update > Swift 4

let loc_coords = CLLocationCoordinate2DMake(47.601089,-52.740439)

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

Thanks

Upvotes: 1

EmptyStack
EmptyStack

Reputation: 51374

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.

Upvotes: 6

Mihai Fratu
Mihai Fratu

Reputation: 7663

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;

Upvotes: 7

Joe
Joe

Reputation: 57169

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

Upvotes: 25

Related Questions