<?php

namespace App\Server;

class Location
{
    private $appKey;
    private $locate;

    public function __construct($appKey)
    {
        $this->appKey = $appKey;
    }

    /**
     * @return string|array
     */
    public function getCity(AddressProvider $data, string $location)
    {
        $data->setKey($this->appKey);
        $type = $data->getType();
        $res  = $data->locateToAddress(['location' => $location, 'get_poi' => 1]);
        if (0 != $res['status']) {
            return $res;
        }
        $city = '';
        if ('qq' == $type) {
            $city = $res['result']['address_component']['city'];
        }

        return $city;
    }
}
