# New GPS coordinates based on location, distance and bearing

## Recommended Posts

Hello,

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))))
EndFunc

Func new_coords(\$lat,\$long,\$distance,\$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)
EndFunc```

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

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...