 # API to calculate distances

I have a Xojo 2019 3.1 desktop app on Mac 10.14.6 and need something like a google maps API to calculate the distance between 2 addresses. Do not need to display any maps or other graphics.

Any Suggestions???

Why not subscribe to the Google Maps API?
and distance? driving distance or as the crow flies?

1 Like

You can also look in TOF as something similar has been discussed there.

1 Like

This is why I asked “driving” or “as the crow flys”

Great Circle gives the “straight” distance between 2 GPS coordinates.

I had a very accurate formula for this that I used to locate all the addresses within X miles of a known hospital… but no longer have access to the source

If you happened to have or could get the latitude and longitude of the two addresses you could convert the php could I use to calculate the distances in miles to Xojo:

\$r = 6371; // add e3 for metres
//degrees * 0.01745329252 = radians
\$d1 = deg2rad(\$the_latitude[\$i]);
\$d2 = deg2rad(\$the_latitude[\$j]);
\$clat = deg2rad(\$the_latitude[\$j] - \$the_latitude[\$i]);
\$clong = deg2rad(\$the_longitude[\$j] - \$the_longitude[\$i]);
\$a = sin(\$clat / 2) * sin(\$clat / 2) + cos(\$d1) * cos(\$d2) * sin(\$clong /2) * sin(\$clong/2);
\$c = 2 * atan2(sqrt(\$a), sqrt(1 - \$a));
\$d = round(\$r * \$c * 0.621371);

Can’t remember where I Googled this from but when I use this for cities, it matches very well with Google results for “distance between a and b”.