Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Geocoder Bundle Laravel Package

1tomany/php-geocoder-bundle

A Symfony bundle wrapping the 1tomany/php-geocoder library, giving you an injectable GeocoderClientInterface for geocoding and reverse geocoding through providers like Google, with simple YAML configuration and a mock provider for testing.

View on GitHub
Deep Wiki
Context7

PHP Geocoder Bundle for Symfony

This package wraps the 1tomany/php-geocoder library into an easy to use Symfony bundle.

Installation

Install the bundle using Composer:

composer require 1tomany/php-geocoder-bundle

Configuration

To change the default configuration, create a file named onetomany_geocoder.yaml in config/packages/ with the following contents and adjust accordingly:

onetomany_geocoder:
    transport:
        http_client: http_client

    google:
        api_key: "%env(GOOGLE_API_KEY)%"
        api_version: v4

    mock: false

The transport uses Symfony's http_client service by default, so the transport block can normally be omitted. The bundle injects Symfony's serializer service into the transport.

The google block is optional. If it is omitted, the Google provider is not registered with the GeocoderClient. The Mock provider is disabled by default and can be enabled in the test environment with the following configuration:

when@test:
    onetomany_geocoder:
        mock: true

Usage

Inject the OneToMany\Geocoder\Contract\GeocoderClientInterface client and use its resources:

use OneToMany\Geocoder\Contract\GeocoderClientInterface;
use OneToMany\Geocoder\Resource\Geocode;
use OneToMany\Geocoder\Resource\Reverse;
use OneToMany\Geocoder\Vendor;

final readonly class GeocodeAddress
{
    public function __construct(
        private GeocoderClientInterface $geocoderClient,
    ) {
    }

    public function __invoke(string $path): void
    {
        $response = $this->geocoderClient->geocode(
            Vendor::Google,
            new Geocode(
                street: '123 Main Street',
                unit: null,
                city: 'Dallas',
                zip: '75205',
                state: 'TX',
                country: null,
            ),
        );

        $response = $this->geocoderClient->reverse(
            Vendor::Google,
            new Reverse(
                latitude: 32.10391494,
                longitude: -96.3931030,
            ),
        );
    }
}

Credits

License

The MIT License

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource