Created
August 20, 2015 11:53
-
-
Save DwainTR/c7181995628d5ffacba2 to your computer and use it in GitHub Desktop.
Displays User's Current Location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import MapKit | |
import CoreLocation | |
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { | |
@IBOutlet var map: MKMapView! | |
var locationManager = CLLocationManager() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
locationManager.delegate = self | |
locationManager.desiredAccuracy = kCLLocationAccuracyBest | |
locationManager.requestWhenInUseAuthorization() | |
locationManager.startUpdatingLocation() | |
} | |
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | |
var currentLocation = locations[0] as! CLLocation | |
var latitude = currentLocation.coordinate.latitude | |
var longtitude = currentLocation.coordinate.longitude | |
var latdelta: CLLocationDegrees = 0.001 | |
var longdelta: CLLocationDegrees = 0.001 | |
var span: MKCoordinateSpan = MKCoordinateSpanMake(latdelta, longdelta) | |
var location: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longtitude) | |
var region: MKCoordinateRegion = MKCoordinateRegionMake(location, span) | |
self.map.setRegion(region, animated: true) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment