简体   繁体   中英

How to create Cost Distance Matrix using google-distance-matrix?

I know how to get distance between 2 locations using

 var distance = require("google-distance-matrix");
 distance.key('API-KEY');
 distance.mode('driving');
 distance.units('imperial');
 var origins = [platlong.toString()];
 var destinations = [dlatlong.toString()];
 distance.matrix(origins, destinations, function(err,Data){
         console.log(Data.rows[0].elements[0].distance.value);
 }};

But how to get Cost Distance matrix of 3 or more locations

[
    [0, 2, 3],
    [2, 0, 4],
    [3, 4, 0]
]

For using VRP Algorithm i need Cost Distance Matrix as of Above.

There is only one way i know to create the Cost Distance matrix is by looping mxn times, ie for 3 locations 3 x 3 = 9 times.

In real time scenario for 15 locations i have to loop 15 x 15 = 225 times

So i need to provide the API-Key for 225 times which will be very costly.

Is there any way for finding the Cost Distance Matrix cheaply instead of looping mxn times by google distance matrix

You could reduce your look ups under the presumption, that the distance A->B is the same a B->A and not doing A->A loop ups. This means for 15 location you could get away with 15*14/2 = 105. This is still quite a lot, but less than half than before.

Host your own routing engine, I use this a lot https://github.com/Project-OSRM/osrm-backend

This option is only useful when there is no need for live data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM