Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions server/src/Support/Geocoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ class Geocoding
*/
public const SEARCH_RADIUS = 2000;

/**
* Geocode a search query to get places.
*
* @param string $searchQuery the query to search for
* @param float|null $latitude optional latitude for location-based search
* @param float|null $longitude optional longitude for location-based search
*
* @return Collection a collection of places
*
* @throws \Exception
*/
/**
* Retrieve the configured Google Maps locale.
*/
public static function getLocale(): string
{
return config('services.google_maps.locale', env('GOOGLE_MAPS_LOCALE', 'en'));
}

/**
* Geocode a search query to get places.
*
Expand All @@ -37,8 +56,9 @@ class Geocoding
public static function geocode(string $searchQuery, $latitude = null, $longitude = null): Collection
{
$httpClient = new Client();
$provider = new GoogleMaps($httpClient, null, config('services.google_maps.api_key', env('GOOGLE_MAPS_API_KEY')));
$geocoder = new StatefulGeocoder($provider, 'en');
$locale = static::getLocale();
$provider = new GoogleMaps($httpClient, $locale, config('services.google_maps.api_key', env('GOOGLE_MAPS_API_KEY')));
$geocoder = new StatefulGeocoder($provider, $locale);

try {
if ($latitude && $longitude) {
Expand Down Expand Up @@ -82,8 +102,9 @@ function ($googleAddress) {
public static function reverseFromQuery(string $searchQuery, $latitude, $longitude): Collection
{
$httpClient = new Client();
$provider = new GoogleMaps($httpClient, null, config('services.google_maps.api_key', env('GOOGLE_MAPS_API_KEY')));
$geocoder = new StatefulGeocoder($provider, 'en');
$locale = static::getLocale();
$provider = new GoogleMaps($httpClient, $locale, config('services.google_maps.api_key', env('GOOGLE_MAPS_API_KEY')));
$geocoder = new StatefulGeocoder($provider, $locale);

if (empty($searchQuery)) {
return collect();
Expand Down Expand Up @@ -128,8 +149,9 @@ function ($googleAddress) {
public static function reverseFromCoordinates($latitude, $longitude, ?string $searchQuery = null): Collection
{
$httpClient = new Client();
$provider = new GoogleMaps($httpClient, null, config('services.google_maps.api_key', env('GOOGLE_MAPS_API_KEY')));
$geocoder = new StatefulGeocoder($provider, 'en');
$locale = static::getLocale();
$provider = new GoogleMaps($httpClient, $locale, config('services.google_maps.api_key', env('GOOGLE_MAPS_API_KEY')));
$geocoder = new StatefulGeocoder($provider, $locale);

if (empty($latitude) && empty($longitude)) {
return collect();
Expand Down