GPSwift allows you to simple connect to CoreLocation framework and returns address in human readable format.
File creates singleton class to provide geo location update data in human readable structure.
Copy GPSwift.swift file to your project.
In viewController just create variables of CLLocationManager
and GPSwift
:
var locationManager = CLLocationManager()
var gpsLocation: GPSwift!
Create singleton instance:
gpsLocation = GPSwift.sharedGPS
Then just simple start locating:
gpsLocation.startLocating()
or stop locating:
gpsLocation.stopLocating()
After succesfull location update GPSwift singleton post observer named locationChangedNotification
. So add observer to viewController like this:
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "locationHasChanged",
name: locationChangedNotification,
object: nil)
Then use function locationHasChanged
to read geo located address:
func locationHasChanged() {
println("\(gpsLocation.address.thoroughfare)")
println("\(gpsLocation.address.subThoroughfare)")
println("\(gpsLocation.address.locality)")
println("\(gpsLocation.address.postalCode)")
println("\(gpsLocation.address.ISOcountryCode)")
}
And that's it.
Happy geo locating.