Astronomical altitude from iOS device - ios

How can I retrieve the astronomical altitude that an iOS device is pointed towards? The goal is to be able to point the devices camera at the sky and have it display the altitude.
Astronomical altitude is the angle between an object and the observer's local horizon. This is different then the altitude returned from the location manager. More info: http://en.wikipedia.org/wiki/Altitude_(astronomy)

There is no altitude or similar returned by a CLLocationManager.
What you need is CMMotionManager.
Start a timer with the readout frequency of your choice and read the attitude of your CMMotionManager. Remember to create only one instance of CMMotionManager.
The CMAttitude object has a property called pitch which gives you the rotation around a lateral axis that passes through the device from side to side. So basically it is the same as your desired altitude.

Related

Accelerometer, Gyro, and Magnetometer

I'm new to Core Motion and I'm very confused. Can somebody please explain what these inputs measure and how they can be useful in simple terms?
Accelerometers measure movement relative to gravity, by virtue of "feeling" the force of movement applied to the device. Force of movement can be described as the rate of acceleration and deceleration of the device, hence the name of this sensor.
Gyroscopes measure changes in rotation by virtue of a suspended element reporting its rotation relative to the device. As the device rotates, this suspended element doesn't rotate, so there's a report coming from it that tells you how far the phone's rotated.
Magnetometers get their idea of rotational position from the north/south magnetic fields that compasses use to know where they are relative to the poles. This data is used (primarily) to help the Gyroscope, because these things suffer from float and inertia.
Combined, the information from these sensors, when filtered well (which Apple does for you with CoreMotion) give you all the movement of a phone.
So you can know if the user is swinging the phone around like a table tennis bat, or steering like a Wii Remote Mario style game controller, or simply walking.

What's the difference between distance from CLLocationManager and CMPedometer

I'm writing a running app according to an online tutorial on http://www.raywenderlich.com/97944/make-app-like-runkeeper-swift-part-1.
In the tutorial,the distance the user has run since the start is calculated from two latest recorded locations using "distanceFromLocation" method in CLLocation. However in CMPedometer there's also a distance data which can be retrieved directly. So which one should I use and why?
Thanks
CMPedometer relies on the motion tracking chips built into modern iPhones to measure steps and distance travelled by the owner of the device. It is able to estimate the number of steps taken using motion data, and extrapolate the distance traveled by the user using step counts and estimated stride length. If a distance estimate is good enough for your purposes, then CMPedometer is an easy, power efficient solution to tracking distance travelled.
On the other hand, if you would like the reported distance to be as accurate as possible, you should use CLLocation and calculate the distance between each location the user travels through on their workout. This requires more complex code and an accurate GPS signal. As an added benefit, you'll be able to use the location data to, for instance, draw a map of where the user ran on their workout.

True heading and true course of an iphone

I am working on some project where I required to make an app which can tell course of an iphone but without GPS. I can use GPS to get initial fix.
Now I can get true heading using compass but that is the orientation of phone w.r.t north pole not the direction in which phone is moving?
How can I get course using compass.
I have looked at accelerometer also but in most of the stack quesions it is advised not to use acclerometer for distance and speed calculation.
Any help appreciated!!
The 'course' you are referring to is actually the ground speed vector measured by the GPS (measured by combining two or more consecutive GPS readings and calculating the speed using the timestamps : v = dx/dt).
The compass has nothing to do with course. You can hold your iPhone however you want and walk at a certain direction. Your compass is sensitive to your phone orientation, not movement.
The accelerometer, as its name implies, measures acceleration. It would be difficult to deduce your course solely from that information because of noise.
So your solution is found in CLLocation class : properties speed and course
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instp/CLLocation/speed

How to show an iBeacon in a map

Once an app finds a beacon is possible to show both in a map (the device that found the beacon and the beacon itself)? If so how can i do that? I tried work with the distance bit with no success so far.
Unfortunately, you can't just find the exact location of an iBeacon once it's detected. You can only estimate its distance away from the device.
The proximity property tells you the relative distance (far, immediate, or close) that the beacon is away from the device while the accuracy property tells you how accurate that value is; so you can use proximity in combination with accuracy to get a general approximation of the distance. You could also potentially use these properties in combination with the RSSI, i.e. the received signal strength of the beacon, to further approximate the relative distance.
The device on the other hand can be mapped easily by turning on the map's showsUserLocation property.
I suppose your map is a MKMapView. If you know the precise location of the beacon (by having use a GPS to get the coordinates of the beacon when you have installed it) you can add an annotation on your MKMapView.
Take a look at MKMapView - (void)addAnnotation:(id < MKAnnotation >)annotation method for that.
If you don't have a database where to fetch the GPS coordinates of your beacons, there is no way to display them on a map as a beacon knows nothing about its surroundings.
By the way the accuracy property of a CLBeacon object isn't reliable enough for positioning.

Get pitch, roll and yaw relative to geographic north on iOS?

I see that I can retrieve CMAttitude from a device and from it I can read 3 values which I need (pitch, roll and yaw).
As I understand, this CMAttitude object is managed by CoreMotion which is a Sensor Fusion manager for calculating correct results from compass, gyro and accelerometer together (on Android it is SensorManager Class).
So my questions are:
Are those values (pitch, roll and yaw) relative to the magnetic north and gravity?
If above is correct, how can I modify it to give me results relative to the geographic north?
If a device (such as iPhone 3GS) doesn't have an gyroscope, do I have to tell it to Manager or can I just tell it to give me the device's attitude based on the sensors it has (acc + gyro + compas OR acc + compas)
and 2:
iOS 5.0 simplifies this task. CMMotion manager has new method:
- (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)referenceFrame
As reference frame you can use this values:
CMAttitudeReferenceFrameXMagneticNorthZVertical for magnetic north,
CMAttitudeReferenceFrameXTrueNorthZVertical for true north.
If you want to do this with older iOS im afraid you have to calibrate this by yourself using current user location.
Try checkout this resources:
"What's New in Core Motion" WWDC 2011 video,
"Sensing Device Motion in iOS 4" WWDC 2010 video
3.
If device has no gyro, the deviceMotionAvailable property of CMMotionManger will be "NO" (it is equivalent to gyroAvailable property) and you cannot get attitude using device motion. The only thing you can do is to read accelerometer and magnetometer data directly.

Resources