<?php

namespace App\Server;

use App\Server\Location\LocationProvider;

class Location
{
    private $appKey;
    private $locate;

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

    /**
     * @param AddressProvider $data
     * @param string $location
     * @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 ($res['status'] != 0) {
            return $res;
        }
        $city = '';
        if ($type == 'qq') {
            $city = $res['result']['address_component']['city'];
        }
        return $city;
    }
}
