Location.php 743 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Services;
  3. class Location
  4. {
  5. private $appKey;
  6. private $locate;
  7. public function __construct($appKey)
  8. {
  9. $this->appKey = $appKey;
  10. }
  11. /**
  12. * @param AddressProvider $data
  13. * @param string $location
  14. * @return string|array
  15. */
  16. public function getCity(AddressProvider $data, string $location)
  17. {
  18. $data->setKey($this->appKey);
  19. $type = $data->getType();
  20. $res = $data->locateToAddress(['location' => $location, 'get_poi' => 1]);
  21. if ($res['status'] != 0) {
  22. return $res;
  23. }
  24. $city = '';
  25. if ($type == 'qq') {
  26. $city = $res['result']['address_component']['city'];
  27. }
  28. return $city;
  29. }
  30. }