Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Show distance between two points

Hi,

Does anyone know and/or anyone tried to show distance between 2 longitude and latitude points on a map in an application?

This is possible, using the haversine formula and plenty of pages and calculators out there on the internet to do it. However, can this formula be written in the script somehow so when you clicked 2 points/results on the map something would highlight distance betwen them?

Cheers

Chris

10 Replies
robyn369
Partner - Contributor
Partner - Contributor

Hi All,
BELOW IS FOR QLIK SENSE

Highlevel overview:

IF you have a requirement to plot 2 areas (latitudes and longitudes) and if you want to draw circles around then within a said radius, please see the below.


All you need, is a latitude 1, longitude 1 and latitude 2, longitute 2, with key fields in these 2 tables.

Then you need to join both the tables to get them into one table for calculating the distance.

Further, use the haversine formula (just copy paste) and change the fields as required and inline with you data.
Haversine formula: https://community.qlik.com/t5/QlikView-App-Dev/Haversine-formula-to-find-distance-between-two-lat-lo...
use the response with code from kevinpintoka (thanks to him)

Go the GeoAnalytics and use the 'Travel Areas' option.

Script Section:

Cost Value: 10 (in my example 10 km radius)
Cost Field: Blank
Cost Unit: Kilometers (from the above input it will now be 10 KM)
Transportation: Bird
Name: No Change ( leave as it is)
Type: Loaded table
Table Name: specify the table name that contains the distance calculated (from haversine formula) above.
Table Fields: Key field, Latitude1, Longitude1 (i am using latitude 1 since I want to draw circles around this geo point. If you want you can change to latitude 2, longitude 2
Geometry Type: Latitude and Longitude Point
Only load distinct: YES
Location ID Suffix: No change ( leave as it is)

Click Next.
Select the travel areas in the next wizard window.
Insert script and reload.
Note that you may need to reduce the chunk size based on license limitation you have.

If you get an error stating: "dataset is higher than maximum allowed by license", then follow the below link
https://community.qlik.com/t5/Official-Support-Articles/GeoAnalytics-getting-error-QVX-SYNTAX-ERROR-...
(another thanks to this author)
Front End:
Create Geo Map
Add point layer -> add the geopoint_lat1_long1
Add area layer -> add geo_lat2_long2
Add density layer -> add the geopoint_lat1_long1
tip:  under this layer -> properties/appearance/radius (here you can specify in meters)/scale (turn default off and switch custom on/change the weight factor to 45) -> this will change the heatmap and rather appear as circles.
Add line layer -> add the distance_km -> under From, To, width/add lat1_long1 AND lat2_long2 like a from an to line. under properties/appearance/change the line width/ change arrow style and arrow curviness. addtionally you can add the label under label section and just add the distance_km. this will show the actual distance on the gep graph.

Hope that helped someone.

Cheers

Kind Regards,

Robinson