import UIKit
import MapKit
import CoreLocation
class StartViewController: UIViewController, CLLocationManagerDelegate
{
var latitude,longitude: Double?
var obLocatinManager: CLLocationManager?
@IBOutlet var objMapView: MKMapView?
@IBOutlet var standard: UIButton?
@IBOutlet var satellite: UIButton?
@IBOutlet var hybrid: UIButton?
@IBOutlet var mapView: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
edgesForExtendedLayout = UIRectEdge.None
let swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeRight)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadUserLocation() -> Void
{
obLocatinManager?.delegate = self;
obLocatinManager?.distanceFilter = kCLDistanceFilterNone
obLocatinManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters
obLocatinManager?.requestWhenInUseAuthorization()
obLocatinManager?.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let newlocaton = locations[1] as! CLLocation
self.latitude = newlocaton.coordinate.latitude
self.longitude = newlocaton.coordinate.longitude
obLocatinManager?.stopUpdatingLocation()
self.loadMapView()
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
obLocatinManager?.stopUpdatingLocation()
}
func loadMapView() -> Void
{
var latDelta:CLLocationDegrees = 0.2
var longDelta:CLLocationDegrees = 0.2
var objCoor2D: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: self.latitude!, longitude: self.longitude!)
var objCoorSpan: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var region: MKCoordinateRegion = MKCoordinateRegionMake(objCoor2D, objCoorSpan)
self.objMapView!.setRegion(region, animated: false)
}
@IBAction func didtapStandard(sender: UIButton)
{
self.standard?.backgroundColor = UIColor.greenColor()
self.satellite?.backgroundColor = UIColor.clearColor()
self.hybrid?.backgroundColor = UIColor.clearColor()
self.objMapView?.mapType = MKMapType.Standard
self.loadUserLocation()
println(self.longitude)
println(self.latitude)
}
@IBAction func didtapSatellite(sender: UIButton)
{
self.satellite?.backgroundColor = UIColor.greenColor()
self.standard?.backgroundColor = UIColor.clearColor()
self.hybrid?.backgroundColor = UIColor.clearColor()
self.objMapView?.mapType = MKMapType.Satellite
self.loadUserLocation()
println(self.longitude)
println(self.latitude)
}
@IBAction func didtapHybrid(sender: UIButton)
{
self.hybrid?.backgroundColor = UIColor.greenColor()
self.satellite?.backgroundColor = UIColor.clearColor()
self.standard?.backgroundColor = UIColor.clearColor()
self.objMapView?.mapType = MKMapType.Hybrid
self.loadUserLocation()
println(self.longitude)
println(self.latitude)
}
我试图通过在IOS中使用地图工具包来获取位置但是(位置管理器)这些功能没有被调用