Location.php 676 B

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