| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\api\service;
- class BDService extends BaseService
- {
- /**
- * 道路距离计算
- * @param $origin
- * @param $destination
- * @return \SResult
- */
- public static function shortestPathsAlgorithm($origin, $destination)
- {
- $response = http_request("https://api.map.baidu.com/directionlite/v1/driving",
- [
- "ak" => config("site.baidu_ak"),
- "origin" => $origin,
- "destination" => $destination,
- "steps_info" => 0
- ]
- );
- return new \SResult((int)(0 == $response->status), $response->message, 0 == $response->status ? $response->result->routes[0]->distance : null);
- }
- public static function geocoding($address)
- {
- $response = http_request("https://api.map.baidu.com/geocoding/v3/",
- [
- "ak" => config("site.baidu_ak"),
- "output" => 'json',
- "address" => $address
- ]
- );
- $code = (int)(0 == $response->status);
- return new \SResult(
- $code,
- $code == 0 ? $response->msg : null,
- 0 == $response->status ? ["lng" => $response->result->location->lng, "lat" => $response->result->location->lat] : null
- );
- }
- }
|