读取 GPS 位置时,位置管理器中的高度属性在 iPhone 上返回零

发布于 2024-10-28 18:51:57 字数 995 浏览 8 评论 0原文

我正在编写一个使用 GPS 的应用程序。我可以成功获取纬度、经度和其他属性,但海拔似乎总是返回“0.00”我有以下代码以最简单的方式测试它,仍然得到0.00。下面的代码:

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{


// Stop updating location if renewed in less than 60 seconds
    if ([self timeBetweenLocationandNow] < 60)
{
    [locationManager stopUpdatingLocation]; 
    NSLog(@"GPS Stopped");
}


NSLog(@"Altitude:%.2f m",newLocation.altitude);
}

对可能出现的问题有什么想法吗?另外,关于 init 方法,我有以下内容:

- (id)init
{
self = [super init];

if (self != nil)
{
    // Create location manager Object
    locationManager = [[CLLocationManager alloc] init];
    // Set the delegate to this object
    [locationManager setDelegate:self];
    // Set distance filter and accuracy 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];
 }

return self;
}

将不胜感激任何见解。谢谢

I am writing an app, that uses GPS. I can get successfully the latitude, longitude and other properties, but altitude seems to always return "0.00" i have the following code to test it in the most simplest way and still get 0.00. Code below:

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{


// Stop updating location if renewed in less than 60 seconds
    if ([self timeBetweenLocationandNow] < 60)
{
    [locationManager stopUpdatingLocation]; 
    NSLog(@"GPS Stopped");
}


NSLog(@"Altitude:%.2f m",newLocation.altitude);
}

Any ideas on what could be wrong ? also on an init method i have the following:

- (id)init
{
self = [super init];

if (self != nil)
{
    // Create location manager Object
    locationManager = [[CLLocationManager alloc] init];
    // Set the delegate to this object
    [locationManager setDelegate:self];
    // Set distance filter and accuracy 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];
 }

return self;
}

Will appreciate any insight. thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笙痞 2024-11-04 18:51:57

我不是专家,但这就是我的理解:iPhone 与其他 GPS 系统有很大不同,因为它可以通过多种方式确定您的位置。 iPhone 通过三种方式确定位置:本地 WiFi 信号、手机信号塔和/或 GPS 芯片。使用 GPS 卫星查找位置的速度可能非常慢,而且在人口稠密的城市中几乎无法接收信号。因此,iPhone 通常首先考虑前 2 个选项。

Wifi 定位数据来自人们在街道上行驶记录热点的情况,这显然不会给出太多的海拔高度提示。我不确定手机信号塔三角测量是否提供任何高度数据,但我的猜测是否定的。与 GPS 相比,这两种方法速度非常快,但如您所见,会产生 0 高度。如果您所在的地方 GPS 卫星接收信号良好,iPhone 可能会为您提供海拔高度,但即便如此,它也可能无法找到它,直到它收到几次卫星信号并多次呼叫位置委托为止,即便如此,GPS 的高度数据也可能非常不准确。

长话短说,依靠 iPhone 提供的准确高度数据并不是一个好主意。

I'm no expert but this is how I understand it: The iPhone is quite different from other gps systems because of the multiple ways in which it goes about figuring out your location. The iPhone figures out the location in three ways: local wifi signals, cell towers, and/or gps chip. Using a gps satellite to find a position can be extremely slow and reception can be pretty much non-existent in populated cities. Therefore, iPhone generally looks to the first 2 options first.

Wifi positioning data comes from people driving around on the streets logging hotspots which obviously isn't going to give much of a hint of an altitude. I'm not sure if cell tower triangulation gives any altitude data but my guess is no. These two methods are extremely fast compared to gps but will yield an altitude of 0 as you have seen. If you are in a place where there is a decent gps satellite reception the iPhone may give you the altitude, but even then, it might not even find it till it has received the satellite signal a few times and called the location delegate multiple times, and even then altitude data for gps can be notoriously inaccurate.

Long story short, it's a bad idea to count on accurate altitude data from the iPhone.

清风挽心 2024-11-04 18:51:57

我发现了问题。正如 Deepmist 所建议的,必须多次召集代表。第一次修复后我就停止了 GPS。这为我提供了准确的坐标数据,但高度一直保持在 0.00 左右,直到大约 3 个代表致电。现在我得到了高度数据,有什么好方法来检查这个数据?这样我可以在获取数据后停止位置管理器吗?我可以检查海拔高度是否为非零值,但想知道是否应该使用其他属性来确保您拥有尽可能高的精度,使所有位置数据有效(即某些属性上的非零值) )。谢谢

i found the problem. As Deepmist suggested the delegate has to be called several times. I was stopping the GPS after the first fix. Which was giving me accurate data for coordinates but altitude remained @ 0.00 until like 3 or so delegate calls. Now i get the altitude data, what is a good way to check for this ? so i can stop the location manager after i get the data ? i can check that altitude is a non-zero value, but was wondering if there are other properties that should be used instead to make sure that you have the highest accuracy possible making all of your location data valid (i.e non-zero on some properties). thank you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文