I'm trying to implement a small radar that plots targets based on latitude and longitude coordinates similar to the radar in the Layar AR iPhone app. I have the compass and locationManager working to get the lat/lon, heading and distance between two points. However I'm having trouble plotting the points onto the x-y plane. Could you point me in the right direction(so-to-speak)?
This is the method that I am using to get the heading between two sets of coordinates:
Code:
-(float) getHeadingFromCoordinate:(CLLocation*)fromLocation toCoordinate:(CLLocation*)toLocation
{
float flat = fromLocation.coordinate.latitude;
float flon = fromLocation.coordinate.longitude;
float tlat = toLocation.coordinate.latitude;
float tlon = toLocation.coordinate.longitude;
//convert to radians
flat = (M_PI * flat)/180;
flon = (M_PI * flon)/180;
tlat = (M_PI * tlat)/180;
tlon = (M_PI * tlon)/180;
float heading = atan2(sin(tlon-flon)* cos(tlat), cos(flat)*sin(tlat)-sin(flat)*cos(tlat)*cos(tlon-flon));
return heading;
}
This si the method I am using to plot but the results are not correct:
Code:
-(void) addTargetIndicatorWithHeading:(float)heading andDistance:(float)distance{
//draw target indicators
//need to convert radians and distance to cartesian coordinates
float radius = 50;
float x0 = 0.0;
float y0 = 0.0;
//convert heading from radians to degrees
float angle = heading * (180/M_PI);
//x-y coordinates
float x1 = (x0 + radius * sin(angle));
float y1 = (y0 + radius * cos(angle));
TargetIndicator *ti = [[TargetIndicator alloc] initWithFrame:CGRectMake(x1, y1, 5, 5)];
[self addSubview:ti];
[ti release];
}