Hi All,
Can any trig or GPS experts help me out here? I'm trying to create a geo-spacial bounding box (rectangle) calculation returning the maximum latitude and longitude using the following method that I've retrieved. I am calling the method once for each of the for bearings: north, south, east and west. With these four values I intend to query my Core Data store for all objects within the box.
-(CLLocation*) offsetLocation:(CLLocation*)startLocation:(double)offsetMeters:(double)bearing {
double EARTH_MEAN_RADIUS_METERS = 6372796.99;
double newLatitude = asin( sin(startLocation.coordinate.latitude) * cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) + cos(startLocation.coordinate.latitude) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(bearing) );
double newLongitude = startLocation.coordinate.longitude + atan2( sin(bearing) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(startLocation.coordinate.latitude), cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) - sin(startLocation.coordinate.latitude) * sin(newLatitude));
CLLocation *tempLocation = [[CLLocation alloc] initWithLatitude:newLatitude longitude:newLongitude];
[tempLocation autorelease];
return tempLocation;
}
The problem is the calculation for the newLatitude offset is definitely incorrect. Given the following:
startLocation: latitude 37.331688999999997, longitude -122.030731 offsetMeters : 1000 bearing : 0 (north)
newLatitude returns -0.36726592610659514 (incorrect).
Any suggestions? I've coded around this particular formula until now and this one has me stumped. I've also tried translating a different formula from PHP to no avail. I figure the above is exactly what I need if it can be tweaked.
Thanks, b.dot