Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 2.45 KB

File metadata and controls

87 lines (63 loc) · 2.45 KB

Geocoder

Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. Additionally, the service allows you to perform the converse operation (turning coordinates into addresses). This process is known as "reverse geocoding".

Dependencies

The Geocoder API requires an http client and a serializer. The library relies respectively on Httplug which is an http client abstraction library and the Ivory Serializer which is an advanced (de)-serialization library.

To install them, read this documentation.

Configuration

By default, the geocoder service is disabled. In order to enable the service, you need to configure it.

Http client and message factory

The http client and message factory are mandatory. They define which http client and message factory the geocoder service will use for issuing http requests.

First, configure the Httplug bundle.

httplug:
    classes:
        client: Http\Adapter\Guzzle7\Client
        message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
    clients:
        acme:
            factory: httplug.factory.guzzle7

Then, configure the Google Map bundle:

ivory_google_map:
    geocoder:
        client: httplug.client.default
        message_factory: httplug.message_factory.default

Format

The format allows you to use json/xml format for your http request:

ivory_google_map:
    geocoder:
        format: json

Api key

The API key allows you to bypass Google limitation according to your account plan:

ivory_google_map:
    geocoder:
        api_key: ~

Business account

The business account allows you to use Google Premium account:

ivory_google_map:
    geocoder:
        business_account:
            client_id: ~
            secret: ~
            channel: ~

Usage

Once you have configured your geocoder service, you can fetch it from the container and use it as explained in the documentation

$request = '1600 Amphitheatre Parkway, Mountain View, CA';
$response = $this->container->get('ivory.google_map.geocoder')->geocode($request);