iOS CoreLocation Altitude

坚强是说给别人听的谎言 提交于 2019-11-30 09:03:57

If you're using startMonitoringSignificantLocationChanges, which was a feature new to iOS 4.0, then you will not get altitude updates. This low-power mode only uses cell towers to figure out a user's location, and this method not report altitude.

More generally, the iPhone has three ways of figuring out your location -- cell towers, wi-fi, and GPS. You will only get altitude when the GPS is being used. So even if you set your desiredAccuracy setting to be really precise to force the device to use GPS, if a user is indoors the iPhone probably won't be able to get a GPS signal and will fallback to cell or wi-fi. In that case, you won't get an altitude. Also consider users who are on an iPod Touch -- it only has the ability to get a location via wi-fi, and thus also won't report an altitude.

Two things you could try. First of all, try setting the location manager's desiredAccuracy to kCLLocationAccuracyBest.

If that doesn't work, try removing [manager stopUpdatingLocation];, and put a NSLog in the didUpdateToLocation with the altitude. Sometimes it needs to narrow down for a bit before it displays the altitude.

From the Core Location Data Types Reference:

The CLLocationDistance data type (the data type for altitude) is a double. The formatter you are using for your stringWithFormat is an integer. You need to cast your altitude to an integer, first, or use a double (%f) formatter.

Core Location does not always report altitude immediately. I usually check for a zero altitude in my "success" delegate method. If the altitude is still 0, I keep checking, otherwise, I turn of CoreLocation.

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