# Distance data - PiAware - Lat/Lon

Hi again all, your favourite newbie…

Having lots of fun with my PiAware, and just wondering about the distance column in the flight table tracker. Its only every empty from what Ive seen, so wondering if a) its missing for any reason and b) if there is a way of calculating the distance based on the lat/lon recorded in comparison to my receiver.

Id just like to select (from my JSON feed), aircraft that came within say 10 miles of me, is the scenario Im trying to create.

Many thanks for any advice or guidance as usual.

Cheers
Simon

Actually think I might have it with a python module named GeoPy.

geopy.distance

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)

Might be useful for someone if it works

Or if you’re feeling really funky and math orientated…

``````from math import sin, cos, sqrt, atan2, radians

# approximate radius of earth in km
R = 6373.0

dlon = lon2 - lon1
dlat = lat2 - lat1

a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
c = 2 * atan2(sqrt(a), sqrt(1 - a))

distance = R * c

print("Result:", distance)
``````

It’s missing because you probably don’t have your location set in dump1090. How you do that depends on whether you are using the piaware image or the package install.

Once it is set, the distance field will be populated. If you want to select aircraft within a certain distance then you’ll have to use the data in aircraft.json and the haversine formula which you’ve already found.

please note that, once populated, the distance is from the receiver to the AC without taking altitude into account. Also, the distance will be in nautical miles by default.