First we get the radius of the earth in either miles or kilometers:
R = 6371 km radius of the earth
Next, we calculate the delta or change between the latitude and longitude points:
Δlat = lat2− lat1
Δlong = long2− long1
Finally, we plug those givens into the formula:
a = sin²(Δlat/2) + cos(lat1) * cos(lat2) * sin²(Δlong/2)
c = 2 * atan2(√a, √(1−a))
d = R * c
For the purpose of this experiment, we also need a data table with the values of IP numbers and their proximity to lat long points in the world. MaxMind has generously provided a free data set of city points for this very purpose. After loading the data points and creating a script that pulls the browser’s IP number, the page gets a list of data back. The detail and quality of the data depends on the data set coverage. However, so far in testing, the results are pretty good for the minimal effort put into the coding.
Uses for something like this could include:
– Add immediate locational feedback on web site analytics without log processing
– Provide web site browsers with geographically specific services
– Provide geographically tailored content on front pages
– Restrict content based on geographic location
Weburban LLC is an iPhone, and Android development studio based in the San Francisco Bay Area, California.