I have an SQLite database, which does not support trig functions. I would like to sort a set of lat,lng pairs in my table by distance as compared to a second lat,lng pair. I'm familiar with the standard haversine distance formula for sorting lat,lng pairs by distance. 

In this case I don't care particularly for precision, my points are separated by large distances, so I don't mind rounding off the distances by treating curves as straight lines.

My question, is there a generally accepted formula for this kind of query? Remember no trig functions!
['https://Stackoverflow.com/questions/6548940', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/475329/']
If your points are within reasonable distance of each other (i.e. not across half the world, and not across the date line), you can make a correction for the difference between latitude and longitude (as a longitude degree is shorter, except at the Equator), and then just calculate the distance as if the earth was flat.

As you just want to sort the values, you don't even have to use the square root, you can just add the squares of the differences.

Example, where `@lat` and `@lng` is your current position, and `2` is the difference correction:

```
select *
from Points
order by (lat - @lat) * (lat - @lat) + ((lng - @lng) * 2) * ((lng - @lng) * 2)

```

You can calculate the difference correction for a specific latitude as `1 / cos(lat)`.

---

Cees Timmerman came up with this formula which also works across the date line:

```
pow(lat-lat2, 2) + pow(2 * min(abs(lon-lon2), 360 - abs(lon-lon2)), 2)

```
Change "\*" with "/" works for me:

select \*
from Points
order by (lat - @lat) \* (lat - @lat) + ((lng - @lng) / 2) \* ((lng - @lng) / 2)