Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Jiri Stepanek
Jiri Stepanek
10,740 Points

How to get longitude and latitude? Swift

Hey there, I tryed to understand CLGeocoder class in CoreLocation framework but my app seems to not working :/ so I decided to ask you there. I wanna get longitude and latitude of my device location and print it for example. How can i do that?

1 Answer

Jayden Spring
Jayden Spring
8,625 Points

Hi Jiri,

http://rshankar.com/get-your-current-address-in-swift/

This article provides a good example. Hope this helps.

Jiri Stepanek
Jiri Stepanek
10,740 Points

Nope, It says "Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 0.)"... :/

Jayden Spring
Jayden Spring
8,625 Points

Are you in the iOS Simulator? If so go to the Menu bar and under Debug > Location you can set your location. Or on the debug output (bottom drawer) in XCode you will see a location icon click that and set a simulated location.

That error means that it basically cant get a location. JAyden

Jiri Stepanek
Jiri Stepanek
10,740 Points

OMG thank u so much :D you were right!

Jayden Spring
Jayden Spring
8,625 Points

Have fun, you can be anywhere you want in the world with the simulator ;)