Giter Club home page Giter Club logo

perch-fieldtype-geocode's Introduction

Perch Geocode Field Type

A Perch CMS field type for geocoding addresses.

Requirements

  • PHP 5.3+
  • Perch CMS v2.3.2

Installation

  1. Copy perch/addons/fieldtypes/geocode into your project $PERCH/addons/fieldtypes directory.
  2. Download PHP Geocoder into $PERCH/addons/fieldtypes/geocode/php-geocoder.

Usage

To use the fieldtype, add into your template as follows:

<perch:content id="address" type="geocode" label="Address" adapter="curl" providers="google_maps openstreetmaps map_quest" required="true" />

Once an address has been successfully geocoded, you'll see a Google Map preview:

screenshot

Adapters

The adapter attributes determines which HTTP adapter to use when geocoding. The choices are curl or socket.

The default adapter is curl.

Providers

The providers attributes determines which service(s) to use for geocoding. They should be seperated by a single space, and will be executed in the order specified, stopping once a provider returns a result.

The available options are google_maps, google_maps_business, bing_maps, openstreetmaps, map_quest, nominatim, geocoder_ca, geocoder_us, ign_openls, data_science_toolkit, yandex, baidu and tomtom.

The default providers are google_maps, openstreetmaps and map_quest.

Provider Configuration

Providers are configured using constants. For example, the Google Maps provider accepts a region, locale and a useSSL parameter upon construction. The constant names are determined by the name of the provider (e.g., google_maps) and the name of the parameter (e.g., region), capitalised and underscored separated.

You should specify constants in your $PERCH/config/config.php file:

<?php
// Your existing Perch configuration…

// Google Maps Provider Configuration.
define('GOOGLE_MAPS_REGION', '');
define('GOOGLE_MAPS_LOCALE', '');
define('GOOGLE_MAPS_USESSL', '');

// Bind Provider Configuration.
define('BING_MAPS_APIKEY', '');
define('BING_MAPS_LOCALE', '');
?>

Check out the PHP Geocoder documentation for more information providers and what parameters their constructors accept.

Note: The specified HTTP adapter is automatically passed to the provider constructor, you only need to configure the remaining parameters.

Accessing Latitude/Longitude Data

The latitude and longitude values, as well as the address entered by the user and any error messages, are stored in the item's JSON:

{
    address":
    {
        "address":      "1218 2nd Avenue South\nLethbridge\nAlberta\nT1J 0E3",
        "addr1":        "1218 2nd Avenue South",
        "addr2":        "",
        "city":         "Lethbridge",
        "state":        "Alberta",
        "postcode":     "T1J 0E3",
        "error":        "",
        "latitude":     49.6974029,
        "longitude":    -112.8277358
    }
}

You can access this information using Perch's perch_content_custom() method:

<?php
$addresses = perch_content_custom('Addresses', array(
	'skip-template' => true,
));

print_r($addresses);

/*
    [0] => Array
        (
            [_id] => 95
            [name] => Media 32
            [_title] => Media 32
            [address] => Array
                (
                    [address] => 1218 2nd Avenue South
                                 Lethbridge
                                 Alberta
                                 T1J 0E3
                    [addr1] => 1218 2nd Avenue South
                    [addr2] =>
                    [city] => Lethbridge
                    [state] => Alberta
                    [postcode] => T1J 0E3
                    [error] =>
                    [latitude] => 49.6974029
                    [longitude] => -112.8277358
                )

            [_page] => *
        )
*/
?>

perch-fieldtype-geocode's People

Contributors

ziadoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

perch-fieldtype-geocode's Issues

Perch 3

Does the field type still work with Perch 3? Is there anything I need to update?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.