Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, I am trying to create a slider for distance that would go from 1 to 100 miles. To set this up I have two variables, a filter, a measure for distance and a dimension to create the filter.
latitude variable:
=First({<postal_code = {"$(=GetFieldSelections(postal_code))"}>} lat)
longitude variable:
=First({<postal_code = {"$(=GetFieldSelections(postal_code))"}>} lon)
A filter called Postal Code that is just a drop down that lets you choose a postal code from the field postal_code.
The measure for distance is called Distance Between Zips and I wrote it like this:
sqrt(
(
(69.1 * (lat - (v_selected_lat))) * (69.1 * (lat - (v_selected_lat)))
) +
(
(69.1 * cos((v_selected_lat)) * (lon - (v_selected_lon))) * (69.1 * cos((v_selected_lat)) * (lon - (v_selected_lon)))
)
)
After that I created a dimension called Distance Filter which is this:
At first I put the Distance Field into a drop down to see if it would work when I chose a zip code from the postal_code filter but it didn't work. The filter actually needs to be a slider.
Is there a better way to do what I am trying to do? I have been trying to piece together a process off of previous tickets like these:
https://community.qlik.com/t5/New-to-Qlik-Analytics/50-km-radius-in-qliksense-maps/td-p/1735868
https://community.qlik.com/t5/QlikView-App-Dev/Show-distance-between-two-points/td-p/561286
Hi @ammarahw ,
there’s a more accurate way to calculate the distance between two points on the Earth using the Haversine formula, which is commonly used for this purpose:
=ACOS(
SIN(RADIANS(lat)) * SIN(RADIANS($(v_selected_lat))) +
COS(RADIANS(lat)) * COS(RADIANS($(v_selected_lat))) *
COS(RADIANS(lon) - RADIANS($(v_selected_lon)))
) * 3959
This formula calculates the great-circle distance between two points on a sphere given their longitudes and latitudes, and 3959 is the Earth's radius in miles.
Anyway, nice job! Hope this can help you improve your app.