geocoder-php / GeocoderLaravel

Geocoder service provider for Laravel
http://geocoder-php.org/GeocoderLaravel/
MIT License
706 stars 102 forks source link

Add output language support #144

Closed xSoulRootx closed 5 years ago

xSoulRootx commented 5 years ago

General Information

GeocoderLaravel Version: ^4.0 Laravel Version: 5.7.* PHP Version: 7.2 Operating System and Version: Ubuntu

Issue Description

Output language in reverse query don't work

Resolve

vendor\geocoder-php\google-maps-provider\GoogleMaps.php

in

public function reverseQuery(ReverseQuery $query): Collection

before

return $this->fetchUrl($url, $query->getLocale(), $query->getLimit(), $query->getData('region', $this->region));

add

        if (null !== $query->getLocale()) {
            $url .= '&result_type='.urlencode($resultType);
        } else {
            $url .= '&language='.env('GOOGLE_MAPS_LOCALE', 'en-US');
        }

or something like this

mikebronner commented 5 years ago

@xSoulRootx I reposted your issue here: https://github.com/geocoder-php/Geocoder/issues/940 Please follow up with it there, as it relates to the underlying package, and not this package. :) Good luck!

andreshg112 commented 5 years ago

This is already implemented but not documented.

            $query = \Geocoder\Query\ReverseQuery::fromCoordinates($this->latitude, $this->longitude)
                ->withData('language', 'es-419')
                ->withData('result_type', 'street_address|route|political');

            /** @var \Illuminate\Support\Collection $results */
            $results = \Geocoder\Laravel\Facades\Geocoder::reverseQuery($query)->get();

            if ($results->count() > 0) {
                /** @var \Geocoder\Provider\GoogleMaps\Model\GoogleAddress $first */
                $first = $results->first();

                $value = $first->getFormattedAddress();
            }