Jump to content
Sign in to follow this  

New GPS coordinates based on location, distance and bearing

Recommended Posts



Based on what I read here and on google I put together the following code:

Func atan2($y, $x)
    Return (2 * ATan($y / ($x + Sqrt($x * $x + $y * $y))))

Func new_coords($lat,$long,$distance,$dir)
    $earthRadius = 6371
    $lat1 = _Radian($lat)
    $lon1 = _Radian($long)
    $bearing = _Radian($dir);
    $lat2 = asin(sin($lat1) * cos($distance / $earthRadius) + cos($lat1) * sin($distance / $earthRadius) * cos($bearing))
    $lon2 = $lon1 + atan2(sin($bearing) * sin($distance / $earthRadius) * cos($lat1), cos($distance / $earthRadius) - sin($lat1) * sin($lat2))

    return _Degree($lat2)&","&_Degree($lon2)

The function receives as input the current location (for example: 48.4456 , 2.298889) the distance in km and the bearing (0,90,180 etc) for which to generate new GPS coordinates.

However, for some reason, in certain cases (I guess due to moving on the map, and passing geographical parallels?) the new coordinates are wrong and just overlap older coordinates. This doesn't happen all the time so I have no idea what's wrong.

Can anyone tell me if my function is wrong by design and maybe point me in the right direction (maybe if there already is such an UDF I couldn't find...)?

Thank you


EDIT: pffff... Sorry, wrong forum section. can a mod please move it to the right place? Sorry again :(



Edited by alexandruc

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.