Find point given lati/long offset, heading and distance

Hi all,

Given a start point (in latitude/longitude), initial heading (0 - 360 degrees), and distance (in meters), I am trying to find a second point, B. I've tried several solutions, amongst the closest being:

Code:

`lat = asin(sin(lat1)*cos(distance)+cos(lat1)*sin(distance)*cos(heading))`

IF (cos(lat)=0)

lon=lon1

ELSE

lon=(lon1-asin(sin(heading)*sin(distance)/cos(lat))+pi % (2*pi))-pi

ENDIF

(obtained from Aviation Formulary V1.45)

The above didn't work, returning a wrong co-ordinate (e.g. if point B is due north, it would appear NW or NE etc)

After googling extensively, I managed to piece together the following (again without avail):

Code:

` heading = toRadians(heading);`

lat = toRadians(lat);

lon =toRadians(lon);

angularDistance = distance / WGS84_EARTH_RADIUS;

newLat = asin(

sin(lat) * cos(angularDistance)

+ cos(lat) * sin(angularDistance) * cos(heading));

dlon = atan2(

sin(bearing) * sin(angularDistance) * cos(lat),

cos(angularDistance) - sin(lat) * sin(newLat));

newLong = ((lon + dlon + PI) % (PI * 2)) - PI;

I'm sure that the problem is a simple one, however given how long it has been since I last did geometry....

Any suggestions?

Thanks for your time :-)