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

萝らか妹 提交于 2019-11-30 10:07:27
nvuono

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 <double>...</double> 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

To answer your original question: GPS will always be used if you set desiredAccuracy to Best or BestForNavigation, and distanceFilter to kCLDistanceFilterNone when configuring the CLLocationManager. You will then also get altitude values in the CLLocation event.

However, it takes a short while before the GPS has "locked in" to enough satelites to be able to report the altitude. During that time it will report CLLocation events without altitude values. Therefore, you should ignore the first couple of events until the verticalAccuracy value is good enough for you. Also, check the timestamp, because sometimes the first CLLocation event is an old one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!