Splunk Search

Geographical distance calculation in Splunk Cloud (replacing haversine)

rcornett
New Member

Hi all,

 

We are currently migrating from Splunk on-premise to the Cloud. One of the apps we heavily use is haversine to calculate the distance between 2 locations.

 

I haven't been able to find a cloud-ready replacement for this. Just looking for recommendations on an app or solution to be able to do this in the cloud?

 

Cheers,

Ryan

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@rcornett 

I created a haversine macro (from macros.conf)

[haversine(4)]
args = source_lat, source_lon, dest_lat, dest_lon
definition = eval hv_rlat1 = pi()*$dest_lat$/180, hv_rlat2=pi()*$source_lat$/180, hv_rlat = pi()*($source_lat$-$dest_lat$)/180, hv_rlon= pi()*($source_lon$-$dest_lon$)/180 \
| eval hv_a = sin(hv_rlat/2) * sin(hv_rlat/2) + cos(hv_rlat1) * cos(hv_rlat2) * sin(hv_rlon/2) * sin(hv_rlon/2) \
| eval hv_c = 2 * atan2(sqrt(hv_a), sqrt(1-hv_a)) \
| eval distance = round(6371 * hv_c * 1000,0)\
| fields - hv_rlat, hv_rlat1, hv_rlat2, hv_rlon, hv_rlon1, hv_a, hv_c
iseval = 0

 Here's the distance from Sydney to San Francisco

| makeresults
| eval source_lat=-33.8688, source_lon=151.2093, dest_lat=37.7749, dest_lon=-122.4194
| `haversine(source_lat, source_lon, dest_lat, dest_lon)`
| eval distance_in_km=distance/1000
| table distance_in_km

Hope this helps

 

0 Karma

rcornett
New Member

@bowesmana awesome, thank you! I will give it ago and see if it works with our current application. Thank you 🙂

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@rcornett 

If it works for you, please remember to mark is as the solution, so others can make use of it

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...