2017 © Pedro Peláez
 

propel-behavior propel2-geocodable-behavior

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

image

nolazybits/propel2-geocodable-behavior

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  • Tuesday, September 12, 2017
  • by nolazybits
  • Repository
  • 2 Watchers
  • 2 Stars
  • 718 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 18 Forks
  • 0 Open issues
  • 17 Versions
  • 9 % Grown

The README.md

GeocodableBehavior

Build Status, (*1)

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records., (*2)

This behavior uses Geocoder, the Geocoder PHP 5.3 library and requires Propel 2.0-dev and above., (*3)

Installation

You need to add it to composer.
Propel will automatically add it to the list of available behavior, (*4)

{
  requires:
  {
    zeflasher/propel2-geocodable-behavior": "dev-master"
  }
}

Usage

Just add the following XML tag in your schema.xml file:, (*5)

``` xml , (*6)


Basically, the behavior will add: * two new columns to your model (`latitude` and `longitude`); * four new methods to the _ActiveRecord_ API (`getDistanceTo()`, `isGeocoded()`, `getCoordinates()`, and `setCoordinates()`); * three new methods to the _ActiveQuery_ API (`withDistance()`, `filterByDistanceFrom()`, `filterNear()`). ### ActiveRecord API ### `getDistanceTo()` returns the distance between the current object and a given one. The method takes two arguments: * a geocoded object; * a measure unit (`KILOMETERS_UNIT`, `MILES_UNIT`, or `NAUTICAL_MILES_UNIT` defined in the `Peer` class of the geocoded model). `isGeocoded()` returns a boolean value whether the object has been geocoded, or not. `getCoordinates()`, `setCoordinates()` allows to quickly set/get latitude, and longitude values. ### ActiveQuery API ### `withDistance()` takes three arguments: * a latitude value; * a longitude value; * a measure unit (`KILOMETERS_UNIT`, `MILES_UNIT`, or `NAUTICAL_MILES_UNIT` defined in the `Peer` class of the geocoded model); It will add a `Distance` column on your current query and returns itself for fluid interface. Example use: combine with `orderByDistance()` and `limit()` to return closest matches. `filterByDistanceFrom()` takes five arguments: * a latitude value; * a longitude value; * a distance value; * a measure unit (`KILOMETERS_UNIT`, `MILES_UNIT`, or `NAUTICAL_MILES_UNIT` defined in the `Peer` class of the geocoded model); * a comparison sign (`Criteria::LESS_THAN` is the default value). It will add a filter by distance on your current query and returns itself for fluid interface. `filterNear` takes three arguments: * a model object; * a distance value; * a measure unit (`KILOMETERS_UNIT`, `MILES_UNIT`, or `NAUTICAL_MILES_UNIT` defined in the `Peer` class of the geocoded model). Automatic Geocoding ------------------- At this step, you have to fill in the two columns (`latitude` and `longitude`) yourself. It's not really useful, right ? Automatic geocoding to the rescue! There are two automatic ways to get geocoded information: * using IP addresses; * using street addresses. It provides a `geocode()` method that autoupdate the location values. To prevent autofill when modified, just set `auto_update` attribute to false. This method returns a [`ResultInterface`](https://github.com/geocoder-php/Geocoder/blob/master/src/Geocoder/Result/ResultInterface.php) object, so you can override this method to fill in more fields depending on your model: ``` php <?php class MyObject extends BaseMyObject { // ... /** * {@inheritdoc} */ public function geocode() { if (null !== $result = parent::geocode()) { if ($city = $result->getCity()) { $this->setCity($city); } } return $result; } }

Note: You can use both at the same time., (*7)

IP-Based Geocoding

To enable the IP-Based geocoding, add the following configuration in your schema.xml file:, (*8)

``` xml , (*9)


The `geocoder_api_key_provider` can be either a static method returning the api key. A class method in the format `class()->method()` or `class()->method()->subMethod()`, or a class implementing `getGoogleMapsKey` which must return the key. By default, the default Geocoder `provider` is `YahooProvider` so you'll need to fill in an API key. If you want to use another provider, you'll need to set a new parameter: ``` xml <parameter name="geocoder_provider" value="\Geocoder\Provider\HostIpProvider" />

Read the Geocoder documentation to know more about providers., (*10)

This configuration will add a new column to your model: ip_address. You can change the name of this column using the following parameter:, (*11)

``` xml , (*12)


The behavior will now use the `ip_address` value to populate the `latitude`,and `longitude` columns thanks to **Geocoder**. ### Address-Based Geocoding ### To enable the Address-Based geocoding, add the following configuration: ``` xml <behavior name="geocodable"> <parameter name="geocode_address" value="true" /> <parameter name="geocoder_api_key" value="<API_KEY>" /> </behavior>

By default, the default Geocoder provider is YahooProvider so you'll need to fill in an API key but keep in mind it's an optional parameter depending on the provider you choose., (*13)

If you want to use another provider, you'll need to set a new parameter:, (*14)

``` xml , (*15)


Read the **Geocoder** documentation to know more about providers. Basically, the behavior looks for attributes called street, locality, region, fpostal_code, and country. It tries to make a complete address with them. As usual, you can tweak this parameter to add your own list of attributes that represents a complete street address: ``` xml <parameter name="address_columns" value="street,locality,region,postal_code,country" />

These parameters will be concatenated and separated by a comma to make a street address. This address will be used to get latitude and longitude values., (*16)

Now, each time you save your object, the two columns latitude, and longitude are populated thanks to Geocoder., (*17)

HTTP Adapters

Geocoder provides HTTP adapters which can be configured through the behavior. By default, this behavior uses the CurlHttpAdapter., (*18)

If you want to use another adapter, you'll need to use the following parameter:, (*19)

``` xml , (*20)


Read the **Geocoder** documentation to know more about adapters. Parameters ---------- ```xml <behavior name="geocodable"> <parameter name="auto_update" value="true" /> <parameter name="latitude_column" value="latitude" /> <parameter name="longitude_column" value="longitude" /> <parameter name="type" value="DOUBLE" /> <parameter name="size" value="11" /> <parameter name="scale" value="8" /> <!-- IP-Based Geocoding --> <parameter name="geocode_ip" value="false" /> <parameter name="ip_column" value="ip_address" /> <!-- Address-Based Geocoding --> <parameter name="geocode_address" value="false" /> <parameter name="address_columns" value="street,locality,region,postal_code,country" /> <!-- Geocoder --> <parameter name="geocoder_provider" value="\Geocoder\Provider\YahooProvider" /> <parameter name="geocoder_adapter" value="\Geocoder\HttpAdapter\CurlHttpAdapter" /> <parameter name="geocoder_api_key" value="false" /> <parameter name="geocoder_api_key_provider" value="false" /> </behavior>

This is the default configuration., (*21)

Credits

William Durand william.durand1@gmail.com
Xavier Martin zeflasher+geocodable@gmail.com, (*22)

https://github.com/collectiveidea/acts_as_geocodable, (*23)

The Versions

12/09 2017

dev-master

9999999-dev

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

geocoding geolocation behavior propel location propel2 geocodable

08/08 2017

1.2.2

1.2.2.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

geocoding geolocation behavior propel location propel2 geocodable

01/08 2014

1.2.1

1.2.1.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

geocoding behavior propel geocodable

02/02 2014

1.2.0

1.2.0.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

geocoding behavior propel geocodable

23/01 2014

1.1.0

1.1.0.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

geocoding behavior propel geocodable

26/08 2013

1.0.11

1.0.11.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

The Development Requires

geocoding behavior propel geocodable

10/02 2013

1.0.10

1.0.10.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

The Development Requires

geocoding behavior propel geocodable

09/01 2013

1.0.9

1.0.9.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

MIT

The Requires

 

The Development Requires

geocoding behavior propel geocodable

27/11 2012

1.0.8

1.0.8.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

13/08 2012

1.0.7

1.0.7.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

13/08 2012

1.0.6

1.0.6.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

13/06 2012

1.0.5

1.0.5.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

29/05 2012

1.0.4

1.0.4.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

12/05 2012

1.0.3

1.0.3.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

06/05 2012

1.0.2

1.0.2.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

30/04 2012

1.0.1

1.0.1.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable

22/04 2012

1.0.0

1.0.0.0

The GeocodableBehavior helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.

  Sources   Download

The Requires

 

The Development Requires

geocoding behavior propel geocodable