TencentMapService.php 867 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Services;
  11. class TencentMapService
  12. {
  13. private $key = 'XZ6BZ-TFK2R-L53WL-WYB2F-ZSRIO-VCBNX';
  14. public function geocoder($lat, $lng)
  15. {
  16. $key = $this->key;
  17. $url = "https://apis.map.qq.com/ws/geocoder/v1/?location={$lat},{$lng}&key={$key}";
  18. $client = new \GuzzleHttp\Client();
  19. $data = $client->request('get', $url, [
  20. 'headers' => [
  21. 'Accept' => 'application/json',
  22. ]
  23. ])->getBody()->getContents();
  24. $data = js2php($data);
  25. if ($data['status']) {
  26. return false;
  27. }
  28. return $data['result'];
  29. }
  30. }