Getting Altitude(height from sea level) of my location in iphone SDK

前端 未结 2 983
南笙
南笙 2021-01-01 02:04

I am trying to get Altitude of my location in my application. But every time I try altitude property of CLLocation object I am getting 0.00

2条回答
  •  不知归路
    2021-01-01 02:37

    See Android - Get Altitude By Longitude and Latitude? there is an Android solution but it is easily adaptable to iOS.

    The answer is to use the USGS Elevation Query Web Service

    From the top answer there, basically you just send an HTML Web request to:

    http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx/getElevation?X_Value=" + 
                 String.valueOf(longitude)   + 
                 "&Y_Value=" + String.valueOf(latitude)             
                 + "&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=true"; 
    

    Then you can parse out the response text from between the ... tags

    Edit: It looks like you might be trying to get elevation outside the United States.

    Google Maps API does provide an Elevation service and documentation at https://developers.google.com/maps/documentation/javascript/elevation

提交回复
热议问题