Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show compass on Screen?

I am new to iOS development. My objective is to show a compass on Screen. I have a latitude and longitude of a certain location. I have gotten my current latitude and longitude by using CLLocation.

I have calculated the distance between two points using an API, but now I want to know the correct direction of my phone N/S/E/W and something like according to correct north pole... I am not sure.

Is there some concept of iPhone north pole and actual north pole?

I want show a line pointing towards the particular longitude and latitude, even if my phone is rotating or moving; the line points towards that point only.

Please help me, where i should proceed now? Any guidance or links/tut will be great.

like image 812
Rohit Singhal Avatar asked Oct 02 '11 19:10

Rohit Singhal


People also ask

How do I activate the Compass on my phone?

Go to Settings > Privacy & Security > Location Services, then turn on Location Services. Tap Compass, then tap While Using the App.

Where do I find the Compass on my phone?

If you are not sure whether you have this on your phone, perform a quick search — the easiest way to look for an app is by tapping on the Google search widget on the home screen and typing in "compass". Otherwise, see if your app drawer has a search bar, or just look for the app manually if you dare to do so.

How do I get the True North Compass on my iPhone?

If you want your iPhone's compass to always point to True North, you can change it by going to Settings > Compass > "Use True North."


1 Answers

This is called the "heading" of a CLLocation.

See the CLLocationManager doc part to configure heading for you app and call startUpdatingHeading to be notified with your heading changes, namely when your iPhone is pointing toward another point.

Then use the standard CLLocationManagerDelegate methods to be informed of heading changes and redraw your line accordingly.

Read the Location Awareness Programming Guide for more info about Location Services and heading, especially this part that even contains sample code.


PS: About the two different north, there is no concept of "iPhone North Pole", that's nothing related the the iPhone itself. In Geographic systems, there are two north references to consider: the Magnetic North Pole, which is defined according to the earth magnetic field, and the True North Pole, which is defined according the rotational axis of the earth.

That's also explained in details in the Location Awareness Programming Guide too (like quite everything; always read Programming Guides which are great and very complete resources in general):

Heading values can be reported relative either to magnetic north or true north on the map. Magnetic north represents the point on the Earth’s surface from which the planet’s magnetic field emanates. This location is not the same as the North Pole, which represents true north. Depending on the location of the device, magnetic north may be good enough for many purposes, but the closer to the poles you get, the less useful this value becomes.

like image 107
AliSoftware Avatar answered Oct 22 '22 15:10

AliSoftware