SimpleViewController

//
//  SimpleTableViewController.swift
//  WOEID
//
//  Created by Park on 11/22/15.
//  Copyright © 2015 Park. All rights reserved.
//

import UIKit
import MapKit
import CoreLocation

class SimpleViewController: UIViewController/*, MKMapViewDelegate, CLLocationManagerDelegate*/ {

var woeid: WOEID!
@IBOutlet weak var aMapView: MKMapView!
let locationManager = CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
print(woeid.description)
self.title = woeid.description

let center = CLLocationCoordinate2D(latitude: woeid.latitude, longitude: woeid.longitude)
let span = MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1)
let region = MKCoordinateRegion(center: center, span: span)
self.aMapView.setRegion(region, animated: true)

let annotation = MKPointAnnotation()
annotation.coordinate = center
annotation.title = woeid.city
annotation.subtitle = woeid.country

self.aMapView.addAnnotation(annotation)
/*
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
*/
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// location delegate
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.aMapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print(“Error: ” + error.localizedDescription)
}

/*
// MARK: – Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}

Leave a Reply

Your email address will not be published. Required fields are marked *