How can we find the angle between two locations defined by latitude or longitude - iphone

I do not want any code but want to get reference that how can we find the angle between two locations defined by Latitude or Longitude...
If you do have reference then Please help me to solve my problem...
Thanx in advance....

The formula to calculate bearing is:
θ = atan2( sin(Δlong).cos(lat2), cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )
Bearing is a direction to move from one location to another location (starting from north and then clockwise). While angle in 2D starts from the east and then counter clockwise. So if an angle is what you need, later you'll need to add 90 degree to the result and then revert it (add minus).
Reference:
http://www.movable-type.co.uk/scripts/latlong.html

try the Atan method
Math.Atan2(x1-x2,y1-y2)

Try this website, it does all the calculations for you. Whereas the formulas, those can be found on wiki or any other sites. I like this site cos it managed to help me settle a lot of problems. And even if this web tool was developed in San Francisco, even I am from Singapore. This will work.
Latitude and Longitude web tool

Related

How to identify whether compass is heading towards the location or not?

I am developing a project in augmented reality where a compass shows the direction to the destination.That works fine but i want to check whether the current heading is pointing towards the destination or not.
Can any one suggest me a method to do it?
I have searched a lot in Google couldn't find any method?
Thanks in advance
You need the absolute bearing from your location to your target location
Unfortunately CLLocation doesn't have a call for this but you can find the algo in this question.
CLLocation Category for Calculating Bearing w/ Haversine function
So lets say the bearing is 90 degrees
Then you get the phone bearing to north.
While you are getting location updates you also have course update with CLLocation.
The course might also be 90 degrees
SO find the difference between the two, 90 - 90 = 0! you are dead on target :) You will need to rationalise the numbers to 0 - 360 in the event say you are facing north (0 degrees) and your target is behind you (180 degrees) resulting in -180. If you end up with a negative number just add 360.
I find the magnetic field compass to be very very fidgety, so it looks much nicer if you have some sort of exponential moving average for changes in the phones bearing.

Calculating the Bearing of A(x1,y1) Relative to B(x2,y2) in iOS

May I know how I should calculate the bearing of one point relative to another? All the formulas I'm seeing on the Internet are for lat/lon coordinates. I'm working with the Cartesian coordinate system here and am unable to find a solution. Please help!
Use atan2 function (IIRC your objective-c should have it).
It gives you a result between -PI and PI. You have to map it to 0-360 if you need it.
Not really an answer to your question, but if you're getting your points using CLLocationManager, each CLLocation has a course property, which gives you the bearing of your journey for the given point. For the actual math, see Axeman's answer.

iOS is it possible to convert CLLocation into some sort of XYZ metric coordinate system?

I'm building an augmented reality game, and working with CLLocation is rather cumbersome.
Is there some way to locally approximate CLLocation as XYZ coordinate, expressed in meters with the origin starting at some arbitrary point (for example the initial position when the game was started)?
Lets say I'm working with a 1 mile radius and do not really care about the curvature of the earth. Is it possible to approximate or somehow simplify the location based calculations for local position tracking?
Alternatively, is there a coordinate system that can be used with CLLocation that also incorporates the roll, pitch, yaw of the CMAttitude as well as compass orientation?
Clarification: As far as I understand, the problem with latitude and longitude is that their units vary in size, depending on the position on the globe. I should've specified that X,Y,Z should be in standard units, like meters or feet.
Thank you!
The Haversine formula may be useful.
I found a good article on it at http://www.jaimerios.com/?p=39 with code examples.
You could get the initial point at the app's launch and calculate the relative points based on the user coordinates as he or she moves. Admittedly, this is not super elegant, but if you are just trying to do some simple comparisons based on the user's location relative to an arbitrary origin, this should work. For the Z, Alex Stone's suggestion of calculating it based on the altitude should be fine.

How To calculate nearest location from user?

In my application i am having 4 places with its longitude and altitude(Given).Now i want to find the nearest place from user.
So anyone can tell me the solution for it or provide me some source code or demo for this.
Thanks to all
Create an CLLocation of the points:
CLLocation* locationx = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
And the compare the points with:
double distance = [userposition distanceFromLocation:locationx];
Keep the nearest location.
Edit:
If you really mean "longitude and altitude" then I dont know how.
just took 10 seconds to ask google and find this, wich describes how to calculate the distance beween two points given latitude and logitude:
http://www.movable-type.co.uk/scripts/latlong.html
all you have to do is calculate the distance to all 4 points and choose the lowest one.
ETDI: i'm sure you're also given the latitude, otherwise you won't even have specific coordinates. if this wasn't a type and you really have to take the altitude into account, take a look at this question at google answers
picknick describes a native class method.
This is probably going to use the Haversine formula (search the web or stackoverflow for discussions) to measure distances.
In my experience, writing your own Haversine is usually faster than using a system/app-provided one, although this is on Windows where COM overhead can be "problematic" as it were!
The Haversine (and many similar geometry-on-the-Earth) formulae can be found here:
http://williams.best.vwh.net/avform.htm
(this is one of my few bookmarks I go back to for reference on a regular basis!)
for example user is at x=0,y=0
Calculate the distance by doing : SquareRoot(x2^2 & y2^2)
You will get a distance. Look through all points and compare which distance is the shortest

How to get directions on the iPhone or iPad

Hi I would like to in my application display something like: you're destination is 400 ft north west.
I currently use the getDistanceFrom method but that only gives me the feet between 2 locations.
Thanks for your help.
You probably should simply use Latitude Longitude equations to calculate the bearing and then set certain ranges of bearings to be SW,S,SE, etc.
http://www.movable-type.co.uk/scripts/latlong.html