1 Reply Latest reply: Oct 20, 2015 9:48 AM by Mark O'Donovan

Hi Community,

I saw a Mike Tarallo video Qlik Sense - Developer Hub - YouTube (about howto create an extension by javascritp - simple table)

and I have a question.

Is it possibile to calculate a distance from <city> to <city>

or

Is it possible to create a map from <city> to <city>?

Howto?

Hi Fabio,

If you are happy using the Google Maps Javascript api here is some code that will help you calculate the distance between 2 markers :

var start = markerArray[0].getPosition();

var end = markerArray[1].getPosition();

var diff = calculateDistances(start,end).miles;

//--------------------------------------

// Purpose: Calculate the distance between 2 markers

//

//--------------------------------------

function calculateDistances(start,end) {

var stuDistances = {};

stuDistances.metres = google.maps.geometry.spherical.computeDistanceBetween(start,end);    // distance in metres rounded to 1dp  --computeDistanceBetween = shortest path

stuDistances.km = Math.round(stuDistances.metres / 1000 *10)/10;                // distance in km rounded to 1dp

stuDistances.miles = Math.round(stuDistances.metres / 1000 * 0.6214 *10)/10;            // distance in miles rounded to 1dp

return stuDistances;

}

Thanks

Mark

techstuffy.com