Search code examples
swiftcllocation

The data type of altitude


This might be quite a weird question and I am trying to figure out the data type of the altitude and I'm not exactly sure if I should call it that. But any suggestions would be super helpful. So the bit of code that I need help with is here:

var latitude:CLLocationDegrees = 0
var longitude:CLLocationDegrees = 0
var speed:CLLocationSpeed = 0
var course:CLLocationDirection = 0
var altitude:CLLocation

As you can see, var altitude:CLLocation is not fully declared because I'm not sure of it's data type. What should I write to complete this declaration? Just to give you some context, here is the full code (I don't think it's necessary to read all of it but here it is):

//
//  ViewController.swift
//  Map Demo My Try
//
//  Created by Jae Hyun Kim on 8/14/15.
//  Copyright © 2015 Jae Hyun Kim. All rights reserved.
//

import UIKit
import MapKit

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    var locationManager = CLLocationManager()

    var latitude:CLLocationDegrees = 0
    var longitude:CLLocationDegrees = 0
    var speed:CLLocationSpeed = 0
    var course:CLLocationDirection = 0
    var altitude:CLLocation

    @IBOutlet weak var longitudeLabel: UILabel!
    @IBOutlet weak var latitudeLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
    }

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


    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print(locations)
        let userLocations: CLLocation = locations[0]
        latitude = userLocations.coordinate.latitude
        longitude = userLocations.coordinate.longitude
        let speed = userLocations.speed
    }




    @IBAction func getInformation(sender: AnyObject) {
        longitudeLabel.text = String(latitude)
        latitudeLabel.text = String(longitude)

    }
}

Any help would be appreciated!


Solution

  • The type of an altitude is CLLocationDistance (as stated in the CLLocation Reference) CLLocationDistance is a typealias for Double.