简体   繁体   中英

How to check the compass heading is pointing to a particular location or not?

I am new to iphone development.I want to know whether there is any method to check a person iphone is pointing towards a particular location or not.I cam to know that there is framework for CLLocation to get the heading of the device.But i also want to check if its poiting towards the right direction also. Destination location is obtained by longitude and latitude.Can any one suggest me a method for it?

thanks in advance

CLLocationManager will give you the heading, Check out the docs here-> https://developer.apple.com/library/mac/ipad/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

Also, check out this answer where they talk about CLLocationDirection and trueHeading -> https://stackoverflow.com/a/2043694/1104563

--- UPDATED

There is no built-in way to do this, you need to use a formula to determine this. The formula can be found here calculate bearing in relation to two points

In addition you can check out this SO answer: CLLocation Category for Calculating Bearing w/ Haversine function

Hope this helps. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM