Given a start point, a distance and a heading, it is possible to work out the resulting latitude and longitude. See the maths behind it here. See Radians Versus Degrees for the utility functions we are going to use in this calculation. There’s an example of a mashup using this at Urbarama mashup

Variables

The variables required to calculate a new lat/lon are:

  1. Origin Latitude and Longitude
  2. Heading in degrees from origin
  3. Distance in kilometers from origin

Together, they can be used to create the latitude and longitude of a new point like this

Code

You will find this code in the google apps script mcpher library or in the downloadable cDataSet.xlsm (usefulStuff module), at this gist, and below

Excel formula version

You may of course want to do all this in an Excel formula. Here’s some data, in this case on Row 5.

new Latitude formula (cell e5)

=ASIN(SIN(A5*PI()/180)*COS(D5/6371)+COS(A5*PI()/180)*SIN(D5/6371)

new Longitude formula (cell f5)

=((B5*PI()/180)+ATAN2(COS(D5/6371)- SIN(A5*PI()/180)*SIN(ASIN(SIN(A5*PI()/180)*COS(D5/6371)+COS(A5*PI()/180)*SIN(D5/6371) *COS(C5))),SIN(C5)*SIN(D5/6371)*COS(A5*PI()/180)))*180/PI()

new latitude formula calling VBA function (cell g5)

=getLatFromDistance(A5,D5,C5)

new longitude formula calling VBA function (cell h5)

=getLonFromDistance(A5,B5,D5,C5)

Take a look at One Liners for more tips like this. In the meantime why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.

You can download this example and all other code in the cDataSet.xlsm from Downloads

Formula attribution

http://www.movable-type.co.uk/scripts/latlong.html

For help and more information join our forum, follow the blog, follow me on twitter