Skip to content

Geocomplete Field Defaults to 'geocode' Type, Limiting Search Results #158

@oswaldocfr

Description

@oswaldocfr

When using the FilamentGoogleMaps\Fields\Geocomplete field, the autocomplete suggestions appear to prioritize only addresses, even when no specific types are set via the ->types() method. This behavior differs from the standard Google Places Autocomplete API, which typically provides a broader mix of addresses and establishments when no type restrictions are applied.

Upon inspecting the package's source code (src/Fields/Geocomplete.php), it's found that the getTypes() method explicitly defaults the types parameter to ['geocode'] if the ->types() method is not called by the user:

public function getTypes(): array
{
    $types = $this->evaluate($this->types);

    if (count($types) === 0) {
        $types = ['geocode']; // This line sets the default to 'geocode'
    }

    return $types;
}

This default setting causes the Geocomplete field to primarily return address-based results, as ['geocode'] is a "Table 3" type in the Google Places API and cannot be mixed with other "Table 3" types like ['establishment']. This prevents a unified search experience for both addresses and businesses without explicit (and limited) type specification.

Proposed Solution

To allow the Geocomplete field to offer a broader range of results (including both addresses and establishments) by default, the package's getTypes() method should be modified to return an empty array ([]) instead of ['geocode'] when no types are explicitly set.

Proposed Change in src/Fields/Geocomplete.php:

--- a/src/Fields/Geocomplete.php
+++ b/src/Fields/Geocomplete.php

         $types = $this->evaluate($this->types);
 
         if (count($types) === 0) {
-            $types = ['geocode']; // Original: Defaults to 'geocode'
+            $types = []; // Proposed: Defaults to an empty array for broader search
         }
 
         return $types;

Changing the default to an empty array ([]) would align the Geocomplete field's default behavior with the standard Google Places Autocomplete API's behavior, allowing for a mix of address and establishment results unless specific types are explicitly defined by the user.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions