# Geolocation

Recall the First Spherical Law of Cosines:

Given a unit sphere, a spherical triangle on the surface of the sphere is defined by the great circles connecting three points $u$, $v$, and $w$ on the sphere. If the lengths of these three sides are $a$ (from $u$ to $v),$ $b$ (from $u$ to $w),$ and $c$ (from $v$ to $w),$ and the angle of the corner opposite $c$ is $C,$ then $$\cos c = \cos a \cos b + \sin a \sin b \cos C$$

In any decent device and for most computer languages, this formula should give well-conditioned results down to distances as small as around three feet, and thus can be used to compute an accurate geodetic distance between two given points in the surface of the Earth (well, ok, assuming the Earth is a perfect sphere). The geodetic form of the law of cosines is rearranged from the canonical one so that the latitude can be used directly, rather than the colatitude, and reads as follows: Given points $p_1$ and $p_2$ with positions $(lat_1, long_1)$ and $(lat_2, long_2)$ respectively, the distance $d$ between the two points is given by the following formula.

$$\cos\displaystyle{\frac{d}{R_\oplus}}=\sin(lat_1)\sin(lat_2) + \cos(lat_1)\cos(lat_2)\cos(long_2-long_1),$$

where $R_\oplus=3,959$ is the radius of the Earth in miles (well, ok, the average radius of the Earth…)

A nice application of this formula can be used for geolocation purposes, and we recently had the pleasure to assist Thumb Mobile to write such functionality for one of their clients.

Go to www.lizardsthicket.com in your mobile device, and click on "Find a Location." This fires up the location services of your browser. When you accept, your latitude and longitude are tracked. After a fast, reliable and resource-efficient algorithm, the page offers the location of the restaurant from the Lizard's chain that is closest to you. Simple, right?

Tizona Scientific Solutions LLC

230 Corley Woods Drive
Lexington, SC 29072

voice: (803) 386-1822
info@tizona-sci.com

Thumb-mobile