How to get directions on the iPhone or iPad - iphone

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

Related

cllocation -distanceFromLocation bad accuracy

i am developing an app which is particularly dependent upon the distance between two iOS devices. I am using GPS location of devices to calculate the distance between them.
To calculate distance, i am using cllocation -distanceFromLocation method but the values generated by method is fluctuating and differs from actual distance between devices and cannot be considered even as an approximate result.
For example, if the actual distance between devices is 2 to 3 meters, it gives me the result around 14 meters at some point and 43 meters at another point. Is the the function -distanceFromLocation: is not so precise and accurate????
Is there any better alternative for calculating distance using GPS latitude and longitude of devices???
Please help me out.
Thanx in advance.
The accuracy of CoreLocation GPS varies greatly depending on your surroundings.
At it's most accurate it can go down to a couple of metres resolution (I'm not sure exactly) but if you're indoors it will be more like 20-50 metres.
I'm guessing that you're developing and testing the app indoors and so the fluctuations would be about normal.
Even outdoors in perfect weather CoreLocation will struggle to accurately tell you the distance between two devices over a short distance. (i.e. a couple metres).
For short range you might be better using wifi signal strength instead. Although this can also change from room to room.
Essentially, it's difficult to accurately detect the distance between two devices.

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.

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.

IOS Core location - Find out nearest branch

I have create a program to find out my current location using IOS corelocation framework.It works fine.
I need to create a program that list nearest branchaes of a shop chain, while a user travel with the phone.My data base contains the branches details with Latitude and lognitude.How i compare with these details to find out the nearest branch.
Help is highly appreciated.Anybody knows any example program
Thanks,
VKS
You can make use of distanceFromLocation: method of CLLocation.
distanceFromLocation:
Returns the distance (in meters) from the receiver’s location to the
specified location.
(CLLocationDistance)distanceFromLocation:(const CLLocation
*)location
Parameters
location
The other location.
Return Value
The distance (in meters) between the two locations.
Discussion
This method measures the distance between the two locations by tracing
a line between them that follows the curvature of the Earth. The
resulting arc is a smooth curve and does not take into account
specific altitude changes between the two locations.
Availability
Available in iOS 3.2 and later.
By using this method to get the distances of the shops with your current location, you can then sort the list based on the distance to get the nearest branch
VKS, I got to solve the exact same problem too now (using apptarget iOS 5). Do you have any example code / snippets / tips to share for this problem, that I assumed you solved a long time ago? The above is very good explanation from 7KV7, but some examples will speed up my process a lot. Thank's :-)

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

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