# Distance between two GPS points not working

Hi, I need to measure the distance between two locations (GPS coordinates)
I found the the following math here: math - Calculate distance between 2 GPS coordinates - Stack Overflow

``````function degreesToRadians(degrees) {
return degrees * Math.PI / 180;
}

function distanceInKmBetweenEarthCoordinates(lat1, lon1, lat2, lon2) {

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
}
``````

And I â€śimportedâ€ť the idea to Kodular as follow:

But when I run, the distance does not match.
I tested the suggested values for lat/long,lat1/long1 and also other coordinates but no good.
I checked the math a number of times and cannot find where I did wrong.

I did create a variable â€śbâ€ť just to make the blocks more readable but it does not change the result.

Help welcome
Paulo

3 Likes

I like that you are trying to build the procedure. @vknow360 also made a extension to calculate this.

4 Likes

Dear Peter, just tested, works 100%.
Thanks
Paulo.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.