我想动态地将一个起点和多个目的地发送到 Google datamatrix api。 如果我们直接使用传递值,效果很好:
service.getDistanceMatrix({
origins: [document.getElementById("origin1").value],
destinations: ["kopargaon", "manmad"],
....
但是如果我们将位置推送到数组中然后传递到目的地,那么它将无法工作。 例如。
service.getDistanceMatrix({
origins: [document.getElementById("origin1").value],
destinations: [loc.toString()],
....
//loc is array of locations
API 将所有数组元素视为单个位置。
最佳答案
您正在将数组转换为字符串,但目标需要数组作为输入。
service.getDistanceMatrix(
{
origins: [document.getElementById("origin1").value],
destinations: [loc], // .ToString converts array to string, Hence removed
....
//loc is array of locations
关于javascript - 如何动态地将多个目的地传递给Google矩阵api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31692391/