Code Monkey home page Code Monkey logo

fuel-geocode's Introduction

#FuelPHP Geocode package

Description

The FuelPHP Geocode package is a FuelPHP package that interacts with the

##What is Geocoding?

Straight from the horse's mouth:

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. The Google Geocoding API provides a direct way to access a geocoder via an HTTP request. Additionally, the service allows you to perform the converse operation (turning coordinates into addresses); this process is known as "reverse geocoding."

##Usage

###Normal Geocoding

$results = \Geocode::address('19 Gateway Boulevarde, Morisset NSW 2264 Australia');

foreach ($results as $result)
{
    echo $result->latitude() . ' ' . $result->longitude();

    echo $result->component('street_number', 'short');

    /**
     * Below is a list of components
     * accessible like:
     * \Geocode_Response_Result::ACT_STREET_ADDRESS
     * or just learn their values as that way is stupid.
     */
    // Indicates a precise street address.
    const ACT_STREET_ADDRESS              = 'street_address';

    // Indicates a named route (such as "US 101").
    const ACT_ROUTE                       = 'route';

    // Indicates a major intersection, usually of two major roads.
    const ACT_INTERSECTION                = 'intersection';

    // Indicates a political entity. Usually, this type indicates a polygon of some civil administration.
    const ACT_POLITICAL                   = 'political';

    // Indicates the national political entity, and is typically the highest order type returned by the Geocoder.
    const ACT_COUNTRY                     = 'country';

    // Indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels.
    const ACT_ADMINISTRATIVE_AREA_LEVEL_1 = 'administrative_area_level_1';

    // Indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.
    const ACT_ADMINISTRATIVE_AREA_LEVEL_2 = 'administrative_area_level_2';

    // Indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
    const ACT_ADMINISTRATIVE_AREA_LEVEL_3 = 'administrative_area_level_3';

    // Indicates a commonly-used alternative name for the entity.
    const ACT_COLLOQUIAL_AREA             = 'colloquial_area';

    // Indicates an incorporated city or town political entity.
    const ACT_LOCALITY                    = 'locality';

    // Indicates an first-order civil entity below a locality.
    const ACT_SUBLOCALITY                 = 'sublocality';

    // Indicates a named neighborhood.
    const ACT_NEIGHBORHOOD                = 'neighborhood';

    // Indicates a named location, usually a building or collection of buildings with a common name
    const ACT_PREMISE                     = 'premise';

    // Indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
    const ACT_SUBPREMISE                  = 'subpremise';

    // Indicates a postal code as used to address postal mail within the country.
    const ACT_POSTAL_CODE                 = 'postal_code';

    // Indicates a prominent natural feature.
    const ACT_NATURAL_FEATURE             = 'natural_feature';

    // Indicates an airport.
    const ACT_AIRPORT                     = 'airport';

    // Indicates a named park.
    const ACT_PARK                        = 'park';

    // Indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty."
    const ACT_POINT_OF_INTEREST           = 'point_of_interest';

    // Indicates a specific postal box.
    const ACT_POST_BOX                    = 'post_box';

    // Indicates the precise street number.
    const ACT_STREET_NUMBER               = 'street_number';

    // Indicates the floor of a building address.
    const ACT_FLOOR                       = 'floor';

    // Indicates the room of a building address.
    const ACT_ROOM                        = 'room';
}

###Reverse Geocoding

$result = \Geocode::reverse(-33.11721220, 151.47154220)->first();

echo $result->formatted_address();

Docs

I will write up docs one day for the package. Until then, have a browse through the classes

fuel-geocode's People

Contributors

bencorlett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

leeovery

fuel-geocode's Issues

Error with Converting

Hey,

I seem to be getting this issue. Do you have any idea how I can resolve this?

RuntimeException [ Error ]: Object class "Geocode\Geocode_Response_Result" could not be converted to string or sanitized as ArrayAccess. Whitelist it in security.whitelisted_classes in app/config/config.php to allow it to be passed unchecked.

I have this in my controller:

$geocode = \Geocode::address('19 Gateway Boulevarde, Morisset NSW 2264 Australia');

This in my View:
foreach ($geocode as $geoc)
{
echo $geoc->latitude() . ' ' . $geoc->longitude();

                    echo $geoc->component('street_number', 'short');

                }

Cheers,

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.