Get height from a specific given point - mapkit

I am trying to determine the height from a certain point, but I am not getting it using my iPad. I determined my height var as follows:

 var altitude: CLLocationDistance = 0.0

I created this function:

       func getAltitude(latitude: CLLocationDistance, longitude: CLLocationDistance) -> CLLocationDistance {

    //Get altitude of touched point
    locationManager.requestWhenInUseAuthorization()
    locationManager.distanceFilter = kCLDistanceFilterNone
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    let touchPointLocation = CLLocation(latitude: latitude, longitude: longitude)
    let altitude = touchPointLocation.altitude

    return altitude

}

For example, when I touch the map, I tried to get such a height, inside longpress:

let touchPoint = gestureRecognizer.location(in: self.map)
let coord = map.convert(touchPoint, toCoordinateFrom: self.map)        //now this coord is working ok. Its touched point coordinates

let altitude = getAltitude(latitude: coord.latitude, longitude: coord.longitude)

print(altitude) //I get 0.0 here :(

Why is this wrong? How can i do this?

+4
source share

Source: https://habr.com/ru/post/1664460/


All Articles