geocoder-php / GeocoderLaravel

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

Region implementation in Google Maps ? #171

Closed mho22 closed 4 years ago

mho22 commented 4 years ago

General Information

GeocoderLaravel Version: ^4.0 Laravel Version: 5.5.45 PHP Version: >=7.0.0 Operating System and Version: MacOS 10.13.6

Issue Description

I can't find any documentation to fully understand how to add actual Region in Laravel Geocoder.php file. I red all f the questions already asnwered back in 2014 but code has changed.

Back in 2014 : 'Geocoder\Provider\GoogleMapsProvider' => ['fr-FR', 'Île-de-France', true] No API Key was asked

in 2020 : 'providers' => [ Chain::class => [ GoogleMaps::class => [ env('GOOGLE_MAPS_LOCALE', 'en_US'), env('GOOGLE_MAPS_API_KEY'), ], GeoPlugin::class => [], ], ],

When I analyze the GoogleMaps class, I find the constructor :

public function __construct(HttpClient $client, string $region = null, string $apiKey = null)
{
    parent::__construct($client);

    $this->region = $region;
    $this->apiKey = $apiKey;
}

No indicators in GoogleMaps are talking about a locale but a region. Am I wrong somewhere, am I confounding the two elements ? How do I add a region to GoogleMaps ?

Thanks for your help,

🇧🇪 Yes, I'm from Belgium and it is a VERY complicated country 🤣

mikebronner commented 4 years ago

Hi @Itemshopp, thanks for dropping by to ask the question. Regions are not the same as you think of them. The Google docs show the following: https://developers.google.com/places/web-service/search (search for region on the page, and look at the description in the options section). They are two-digit country codes or region codes. These do not necessarily correspond to administrative regions.

Further, the region code does not restrict results to only that region. That is something you will have to manually filter after fetching the results.

mho22 commented 4 years ago

Hi @mikebronner , I documented myself about the Google Maps geocode API earlier and found out this thing. When you search about geocode parameters you find that article :

And when it talks about Region and Region Biasing here is the article :

I wanted to highlight this article and especially the example here about Toledo.

I want to restrict [ not fully restrict I undertand but as possible enough ] my geocoding requests to a country. Like this Toledo example from Spain.

Could we use that region parameter or maybe bounds parameter in Geocoder Laravel ?

mikebronner commented 4 years ago

Yes, it is set in the configuration files. If you want to have region bias for Belgium, just set it to "be" instead of "us".

xippios commented 3 years ago

Stumbled across this, as I was wondering the same thing. I understand how it is easily possible to set the region bias in the config, but how would I do this on the fly? Let's say one query should use the be bias and another needs the cl bias?

Thanks for letting me know if this is possible out of the box or if I need to figure something out on my own.

@mikebronner By the way: Great Library and Package 👍