谷歌距离矩阵 API 的发送数组和处理返回匹配 ID [英] Google Distance Matrix API's sending array and processing return to match ID

查看:28
本文介绍了谷歌距离矩阵 API 的发送数组和处理返回匹配 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求改进一个系统,该系统当前将客户地址输入到某些表单字段中,并且在提交时,系统会根据客户地址查询属于员工的郊区数据库.它返回每个工作人员旅行时间/距离的公里数和距离时间,以便提交请求的人知道哪个工作人员可以最快地到达该客户.目前,系统 1 对 1 循环遍历每个工作人员.每次通过它都会查询 google matrix api.超过 45 名工作人员循环执行,需要 15 到 35 秒的时间才能返回整个列表.

I have been asked to improve a system that currently has a customers address imputed into some form fields and when its submitted the system queries a database of suburbs that belong to staff against the customers address. It returns the km's and distance time for each staff members traveling time/distance so the person who submitted the request knows which staff member can get to that customer the quickest. Currently the system loops through each staff member 1 by 1. With each pass through it queries the google matrix api. With 45+ staff to loop through its taking anywhere from 15 to 35 seconds to return the whole list.

我找到了一种方法,可以将一个查询中的所有地址作为 url 传递给 google matrix api 并返回一个数组.它现在下降到不到 1 秒,几乎是即时的.可以看到发送的示例请求 此处:

I have found a way to pass all the addresses through in one query to the google matrix api as a url and return an array. Its now down to less than 1 second and almost instant. An example request sent can be seen here:

我现在遇到的问题.是那些原籍郊区的每一个都被分配给了一个工作人员用户.无法将该员工的用户 ID 或唯一标识符发送到 googles api,反过来我不知道如何返回每个结果并将其与员工郊区进行匹配.

Problem I have now. Is each one of those origin suburbs was assigned to a staff member user. There is no way to send that staff members user id or unique identifier to googles api and in turn im not sure how to return each result and match it against the staff members suburb.

有人有想法吗?

我目前正在使用 php 执行 curl 请求以生成该 url 并从数组中的 google matrix api 获取响应.

Im currently doing a curl request using php to generate that url and get the response from google matrix api in an array.

推荐答案

这是根据 Scopey 的建议通过在两个数组中使用键并匹配它们来修复的.

This was fixed as per Scopey's suggestion by using key in both arrays and matching them.

function array_merge_custom($array1,$array2) {
    $mergeArray = [];
    $array1Keys = array_keys($array1);
    $array2Keys = array_keys($array2);
    $keys = array_merge($array1Keys,$array2Keys);

    foreach($keys as $key) {
        $mergeArray[$key] = array_merge_recursive(isset($array1[$key])?$array1[$key]:[],isset($array2[$key])?$array2[$key]:[]);
    }

    return $mergeArray;

}

这篇关于谷歌距离矩阵 API 的发送数组和处理返回匹配 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆