Tuesday, February 14, 2017

Building iOS Map Applications in Swift 3 (2)

Building iOS Map Applications in Swift 3 (2)
Normally, the general steps for getting longitude and latitude of user location.
  1. Add CoreLocation.framework to BuildPhases -> Link Binary With Libraries (no longer necessary as of XCode 7.2.1)
  2. Add import CoreLocation to your class - probably ViewController.swift
  3. Add CLLocationManagerDelegate to your class declaration
  4. Add
    NSLocationWhenInUseUsageDescription and
    NSLocationAlwaysUsageDescription
    to plist
  5. 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