I want to find a nearest location from following database table
Address Latitude longitude
Kathmandu 44600, Nepal
When the method should perform it is nicer to first filter on latitude and longitude, and then calculate the squared distance approximative. For Nordic countries, it will be about 0.3 percent off within 1000 km's.
So instead of calculatinG the distance as:
dist_Sphere = r_earth * acos ( sin (lat1) * sin (lat2) + cos(lat1)*cos(lat2)*cos(lon 2 - lon 1)
one can calculate the approximate value (assume that lat = lat 1 is close to lat 2) as
const cLat2 = cos lat ^ 2
const r_earth2 = r_earth ^ 2
dist_App ^2 = r_earth2 * ((lat 2 - lat 1) ^2 + clat2 *(lon 2 - lon 1) ^2)
Order by Dist_App 2, and then simply take the square root off the result.