在 iphone SDK 中获取我所在位置的海拔高度(距海平面的高度) [英] Getting Altitude(height from sea level) of my location in iphone SDK

查看:14
本文介绍了在 iphone SDK 中获取我所在位置的海拔高度(距海平面的高度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中获取我所在位置的海拔高度.但是每次我尝试 CLLocation 对象的 altitude 属性时,我都会得到 0.00 作为结果.

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 as result.

我用谷歌搜索了我的查询,我得到了一个类似的问题这里这里.这个链接是说如果我用 wifi 或手机信号塔访问 CLLocation 它将为空.即使我尝试将 desireAccuracy 设置为最好,也不能确保该应用程序将使用 GPS.这也是说如果我在室内,我将无法访问 GPS.

I googled for my query and I got a similar question here and here. This link is saying that if I access CLLocation with wifi or cell tower it will be null. Even if I try to set desireAccuracy to best than even it don't make sure that app will use GPS. It is also saying that if I am indoor that I won't be able to access GPS.

在很多情况下,它不确定应用是否会仅使用 GPS.我也想要一些从 wifi 或手机信号塔获取海拔高度的方法.为此,我在 Google 上进行了更多搜索,我得到了 Google Earth API 但我认为这是针对微软的仅限 .net 技术.

I many cases it its not sure that app will use GPS only. I want some way for getting Altitude from wifi or cell tower too. For that I googled more and I got Google Earth API but I think this is for Microsoft .net technology only.

现在根据这种情况,我认为作为解决方案,我可以在 Microsoft Technology 中创建一个 Web 服务并将我的位置传递到那里,我可以获得高度作为响应,但我不想这样做.

Now according to this situation I think for a solution I can create a web service in Microsoft Technology and pass my location there and I can get altitude as response but I don't want to do this.

谁能建议我如何从 ios 获取我所在位置的高度.有没有可用的方法?如果是,请按正确的方向导航.

Can anyone suggest me how to get my location's altitude from ios. Is there any way available or not? If yes than please navigate me in right direction.

提前致谢.

编辑1

我使用 CLLocationManager 来更新位置,当我得到我的位置时我需要高度.

I used CLLocationManager for updating location and when I get my location I need altitude.

编辑2

根据@fishinear 的回答,我尝试了以下代码:

According to @fishinear's answer I tried following code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    manager = [[CLLocationManager alloc] init];
    [manager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [manager setDistanceFilter:kCLDistanceFilterNone];
    [manager setDelegate:self];
    [manager startUpdatingLocation];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    if ([newLocation verticalAccuracy] >= 0) {
        NSLog(@"Altitude = %lf",newLocation.altitude);
    }
    NSLog(@"Vertical Accuracy : %lf",newLocation.verticalAccuracy);
}

verticalAccuracy 始终为 -1.即使将应用程序运行到最后 30 分钟,它也不会改变.我在我的 3GS 上运行 ios 4.3.2.我在室内,所以我认为它甚至无法使用此代码访问 GPS.

verticalAccuracy is always -1. It is not changing even after running the app to last 30 Mins. I am runnin ios 4.3.2 on my 3GS. I am indoor so I think it is not accessing GPS using this code even.

推荐答案

参见 Android - 通过经度和纬度获取高度? 有一个 Android 解决方案,但它很容易适应 iOS.

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

答案是使用USGS Elevation Query Web Service

从上面的答案来看,基本上你只需发送一个 HTML Web 请求到:

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"; 

然后你可以从 <double>...</double> 标签之间解析出响应文本

Then you can parse out the response text from between the <double>...</double> tags

看起来您可能正试图在美国以外的地方获得海拔.

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

Google Maps API 确实在 https://developers 提供海拔服务和文档.google.com/maps/documentation/javascript/elevation

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

这篇关于在 iphone SDK 中获取我所在位置的海拔高度(距海平面的高度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆