Location.php 784 B

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