Spatie\Geocoder\Google\Geocoder::getCoordinatesForQuery PHP Метод

getCoordinatesForQuery() публичный Метод

Get the coordinates for a query.
public getCoordinatesForQuery ( string $query, null $apiKey = null, null $language = null, null $region = null ) : array
$query string
$apiKey null
$language null
$region null
Результат array
    public function getCoordinatesForQuery($query, $apiKey = null, $language = null, $region = null)
    {
        $requestQuery = [];
        if ($query == '') {
            return false;
        }
        if ($apiKey) {
            $this->apiKey = $apiKey;
        }
        if ($language) {
            $this->language = $language;
        }
        if ($region) {
            $this->region = $region;
        }
        if ($this->apiKey) {
            $requestQuery['key'] = $this->apiKey;
        }
        if ($this->language) {
            $requestQuery['language'] = $this->language;
        }
        if ($this->region) {
            $requestQuery['region'] = $this->region;
        }
        $requestQuery['address'] = $query;
        $response = $this->client->request('GET', $this->endpoint, ['query' => $requestQuery]);
        if ($response->getStatusCode() != 200) {
            throw new Exception('could not connect to googleapis.com/maps/api');
        }
        $fullResponse = json_decode($response->getBody());
        if (!count($fullResponse->results)) {
            return ['lat' => 0, 'lng' => 0, 'accuracy' => self::RESULT_NOT_FOUND, 'formatted_address' => self::RESULT_NOT_FOUND];
        }
        return ['lat' => $fullResponse->results[0]->geometry->location->lat, 'lng' => $fullResponse->results[0]->geometry->location->lng, 'accuracy' => $fullResponse->results[0]->geometry->location_type, 'formatted_address' => $fullResponse->results[0]->formatted_address];
    }