Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
fmazzarelli
Partner - Creator III
Partner - Creator III

google

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>?

Immagine.png

Howto?

1 Reply
markodonovan
Specialist
Specialist

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 = {};

        //alert(start+' ' +end);

        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