How to tell if you're facing a specific CLLocation in iPhone app
So I'm making an Augmented Reality app and I'm a little unsure how to tell, given your current location and heading information and a second location, if you're actually facing that location. I think it has to do with a specific part of the CLLoca开发者_开发百科tion Heading but I'm a little unsure. Any help would be awesome, thanks a lot everyone
I did this once and if I recall, all you need is the coordinates of the locations and the heading. If I understand corrctly, you have to check, whether your current position is north or south and whether it is east or west of your destination.
This can be done easily by checking the latitude / longitude values. Adding the heading, you can calculate a single 'line' which represents the direction you are watching.
Anyways, I did this in opengl, drawing some scene into the iPhone. All I needed to do then, was take the calculations from above and draw the scenery.
I cant tell you the code from memory but I can tell you, that drawing it on a piece of paper with some examples did help :) - and all you need to do it you already seem to have!
I had a quick look at CLLocation APIs, and it doesn't look like they do relative heading. Sounds like you'll want to implement something like a "Great Circle Bearing" algorithm, to get the bearing from your position to the object relative to North, and then use the compass reading to determine when your camera is aligned in that direction. This page is a goldmine of geodetic algorithms.
精彩评论