在打开的购物车 mvc 中使用 api 将客户订单转移到最近的卖家

Divert customer order to nearest seller with use of api in open cart mvc

我在多卖家工作打开购物车MVC 我的工作是使用 api 将客户订单转移到最近的卖家 我在 customerorigin 和 sellerdestination 中存储客户和卖家地址 只有我找到距离 那么我如何使用 google api 代码在打开的购物车中查找距离我的代码在演示索引页面中工作正确但是当我使用 api 方法打开购物车时他的节目 寻找距离,然后找到如何在数据库中存储距离 错误我的代码和错误在这里:- 提供一些代码

Order.php 在

$customerorigin = 数据库中获取的客户地址 $sellerdestination = 卖家地址进入数据库

$from = $customerorigin; $to = $sellerdestination; $data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");

      $data = json_decode($data);
      $time = 0;
      $distance = 0;
  foreach($data->rows[0]->elements as $road) {
       $time += $road->duration->value;
       $distance += $road->distance->value;
      }`

注意:数组到字符串的转换在 注意:未定义 属性: stdClass::$duration in 注意:试图获取 属性 中的非对象 注意:未定义 属性: stdClass::$distance in 注意:试图在 INSERT INTO oc_distance VALUES (9,2,3,0)

中获取非对象的 属性

我想我明白了问题所在,但是没有代码支持,所以我打算编写一个实现,我认为您可以使用它。

首先,您需要获取 customers.have 的位置,然后查看 geolocation 的位置。这将 return 你在 js 中的客户坐标。

现在我假设您的数据库中有商店的坐标。您可以使用 google api 来查找它们之间的距离,或者还有一个简单的公式来计算位移但是由于存储,我认为您会更倾向于 google 映射的距离有一个整洁的 api for.

希望这对您有所帮助