I have taken a re-look at this and have found what is possibly an easier way to get the distance between two points other than using the Haversine Formula.
The questions previously asked "how to find the closest place to a pre-defined location if you have a mySQL or SQLite database with lat/lon data" will have two possible answers, namely, "The Straight Distance between the two points" or Secondly, "The Driving (or road) distance between two points". These two can differ vastly and to address this issue with only a few lines of code, here is my contribution
Dim loc1, loc2 As Location
Dim Lat, Lon, DevLat, DevLon As String 'DevLat = Developers Latitude (My Office Lat and lon)
Lat = "-25.676923" ' Destination Lat
Lon = "28.174359" ' Destination Lon
DevLat = "-25.677337" 'DevLat = Developers Latitude (My Office Lat and lon)
DevLon = "28.160202" 'DevLon = Developers Latitude (My Office Lat and lon)
loc1.Initialize2(DevLat, DevLon)
loc2.Initialize2(Lat, Lon)
Log(Round2((loc1.DistanceTo(loc2)/ 1000),2) &" km's") '1.42km's'
As you will notice with the above given information the distance between the two points is 1.42 km's in a straight line (I presume in a longer distance - following the curvature of the earths surface - this does make a difference) - on the other hand - driving there via a road is actually 2.0 km's !! So if you want to give someone the actual distance to reach the destination point, you can make use of Google's Matrix API and use a URL to extract the data you require. Google will look for your shortest route and return that to you as well as the estimated journey time to the destination.
Use this URL (just get your own API key): (Adjust units= to imperial or metric)
https://maps.googleapis.com/maps/ap...59&destinations=-25.677337,28.160202&key=Your API Key 'Remember to get your key from the Matrix API (you can also separate the destinations with a | (pipe) and the API will accept up to 100 destination locations.
The resultant JSON is:
{
"destination_addresses" : [ "678 Tottum St, Dorandia, Pretoria, 0188, South Africa" ],
"origin_addresses" : [
"243-247 Ben Viljoen St, Pretoria North, Pretoria, 0116, South Africa"
],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "2.0 km",
"value" : 2013
},
"duration" : {
"text" : "5 mins",
"value" : 270
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
which can be extracted with the normal HTTP request and JobDone Sub which will include the Json Parser.
If you look at the above information "value" in both instances give in the first instance the distance in meters and in the second instance in seconds. Interesting !!
I trust that this will help for quick retrieval of the desired information that you, my friends, require.