Normally, the general steps for getting longitude and latitude of user location.
- Add CoreLocation.framework to BuildPhases -> Link Binary With Libraries (no longer necessary as of XCode 7.2.1)
- Add import CoreLocation to your class - probably ViewController.swift
- Add CLLocationManagerDelegate to your class declaration
- Add
NSLocationWhenInUseUsageDescription and
NSLocationAlwaysUsageDescription
to plist - Initialize location manager :
locationManager = CLLocationManager()
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
get User Location By:func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var userLocation:CLLocation = locations[0] as! CLLocation
let long = userLocation.coordinate.longitude;
let lat = userLocation.coordinate.latitude;
//Do What ever you want with it
}
No comments:
Post a Comment