Introduction

A powerful geocoding field type powered by the Google Maps API.

Heads Up: The Geocoder field type is a paid addon! Please checkout our store or ask about our developer partnership for repository access.

Configuration

Below is the full configuration available with defaults values:

"example" => [
    "type"   => "anomaly.field_type.geocoder",
    "config" => [
        "zoom"          => 13,
        "height"        => 400
    ]
]
Configuration
Key Example Description

zoom

10

The input map's zoom.

height

500

The input map's height.

Addon Configuration

A Google maps key can be provided by the field type configuration.

You can set the key by publishing the field type and setting the value:

php artisan addon:publish anomaly.field_type.geocoder

You can also set the key by setting the GEOCODER_KEY value in your .env file.

Installation

The Geocoder field type is a paid addon and requires purchasing from the addon store OR a paid subscription.

Installing from Store Download

You can install the Templates module by downloading the addon and placing it within your site's addon directory:

/addons/{application_ref}/anomaly/*
Installing with Composer Subscription

You can install the Geocoder field type with Composer as a VCS repository if you have a subscription:

{
     "require": {
        "anomaly/geocoder-field_type": "~1.1.0"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/anomalylabs/geocoder-field_type"
        }
    ]
}

Usage

This section will show you how to use the field type via API and in the view layer.

Basic Output

The geocoder field type returns an array of data.

$entry->example;

[
    "address"=> "1 Cupertino Loop",
    "formatted" => "Infinite Loop, Cupertino, CA 95014, USA",
    "latitude" => "37.3320403",
    "longitude" => "-122.0285677",
    "formatted_latitude" => "37.3322109",
    "formatted_longitude" => "-122.0307778"
]

Presenter Output

This section will show you how to use the decorated value provided by the \Anomaly\GeocoderFieldType\GeocoderFieldTypePresenter class.

GeocoderFieldType::image()

The image method returns a generated image of the map area.

Returns: string
Arguments
Key Required Type Default Description

$options

false

array

none

The image options.

$formatted

true

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

Example
$decorated->example->image();
Twig
{{ decorated.example.image()|raw }}
Available Option

Below are a list of available options for the image method's options argument.

Properties
Key Required Type Default Description

scale

false

integer

1

The scale of the map.

zoom

false

integer

The configured zoom.

The zoom of the map.

format

false

string

png

The output format of the image. Valid options are jpg and png.

maptype

false

string

roadmap

The Google maptype. Valid options are roadmap, satellite, hybrid, and terrain.

width

false

integer

150

The width of the resulting image.

height

false

integer

100

The height of the resulting image.

GeocoderFieldType::embed()

The embed method returns an embedded Google map.

Returns: string
Arguments
Key Required Type Default Description

$options

false

array

none

The image options.

$formatted

true

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

Example
$decorated->example->embed()->height(500);
Twig
{{ decorated.example.embed().height(500)|raw }}
Available Options

Below are a list of available options for the embed method's options argument.

Options
Key Required Type Default Description

scale

false

integer

1

The scale of the map.

scrollwheel

false

boolean

true

Set to false to disable scrollwheel interaction.

zoom

false

integer

15

The output map zoom.

height

false

integer

none

The style height in pixels if any of the map div.

GeocoderFieldType::url()

The url method returns the Google Maps URL for the address.

Returns: string
Arguments
Key Required Type Default Description

$formatted

false

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

Example
$decorated->example->url();
Twig
{{ decorated.example.url() }}

GeocoderFieldType::link()

The link method returns an HTML link to the Google Maps URL.

Returns: string
Arguments
Key Required Type Default Description

$title

true

string

none

The link title.

$attributes

false

array

none

The array of HTML attributes of the link.

$secure

false

boolean

True if request is secure.

Force a secure URL.

$formatted

false

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

GeocoderFieldType::position()

The position method returns an array containing the longitude and latitude values.

Returns: array
Arguments
Key Required Type Default Description

$formatted

false

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

Example
$decorated->example->position()['longitude'];
Twig
{{ decorated.example.position().longitude }}

GeocoderFieldType::latitude()

The latitude method is a shortcut to return the value's latitude position.

Returns: float
Arguments
Key Required Type Default Description

$formatted

false

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

Example
$deocrated->example->latitude();
Twig
{{ decorated.example.latitude() }}

GeocoderFieldType::longitude()

The longitude method is a shortcut to return the value's longitude position.

Returns: float
Arguments
Key Required Type Default Description

$formatted

false

boolean

false

Use the formatted address location instead of the potentially adjusted marker location.

Example
$decorated->example->longitude();
Twig
{{ decorated.example.longitude() }}