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?

Shmidt
  • 16,436
  • 18
  • 88
  • 136
Harsh
  • 666
  • 1
  • 10
  • 21
  • Your code looks fine. Try to cast the expression to *CLLocationCoordinate2D*. See if my answer below helps you! – EmptyStack Jul 22 '11 at 13:03

4 Answers4

25

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

Joe
  • 56,979
  • 9
  • 128
  • 135
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;
Mihai Fratu
  • 7,579
  • 2
  • 37
  • 63
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.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
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

Harjot Singh
  • 6,767
  • 2
  • 38
  • 34