Possible Duplicate:
iPhone Compass GPS Direction
Hi, I'm trying to develop an application that use the GPS and Compass of the iPhone in order to point some sort of pointer to a specific location (like the compass always point to the North). The location is fixed and I always need the pointer to point to that specific location no matter where the user is located. I have the Lat/Long coordinates of this location but not sure how can I point to that location using the Compass and the GPS... just like http://www.youtube.com/watch?v=iC0Xn8hY80w this link 1:20' I have already know some procedure heading = atan2( sin(lon2-lon1)*cos(lat2), cos(lat1)*sin(lat2) - sin(lat1)*cos(lat2)*cos(lon2-lon1)) then multiplying by 180/π then add 360 such as -(CLLocationDirection)directionToLocationCLLocati on *)location {
CLLocationCoordinate2D coord1 = self.coordinate; CLLocationCoordinate2D coord2 = location.coordinate;
CLLocationDegrees deltaLong = coord2.longitude - coord1.longitude; CLLocationDegrees yComponent = sin(deltaLong) * cos(coord2.latitude); CLLocationDegrees xComponent = (cos(coord1.latitude) * sin(coord2.latitude)) - (sin(coord1.latitude) * cos(coord2.latitude) * cos(deltaLong));
CLLocationDegrees radians = atan2(yComponent, xComponent); CLLocationDegrees degrees = RAD_TO_DEG(radians) + 360;
return fmod(degrees, 360); } I set a arrow and want to let arrow rotate. but the result is not right. And it doesn't use the current heading. I think it must use current heading combine with the result to rotate the arrow.
So can any one give me some solutions.