8

I am trying to find out altitude from a given point, but I am not getting that with my iPad. I have defined my altitude var like this:

 var altitude: CLLocationDistance = 0.0

I have made this func:

       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 altitude like this, inside the 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?

H.N.
  • 1,207
  • 2
  • 12
  • 28
  • Did you check this question http://stackoverflow.com/questions/26728085/finding-altitude-in-swift – AMAN77 Dec 21 '16 at 15:49
  • 1
    Yes. But that is getting altitude from the point where user is. I want to be able to touch map and get touched point altitude. It's not the same thing :) – H.N. Dec 21 '16 at 15:54
  • https://stackoverflow.com/questions/41269562/mapkit-get-altitude/41271356 it says here that this feature is not supported (( – vtezin Sep 01 '21 at 10:11

0 Answers0