Skip to content
lobostome edited this page Aug 21, 2013 · 3 revisions

Geocoding is a feature as of 0.3.0. A common use case includes searching for a legislator by address. This process includes translating the address to a longitude and latitude and then using those two geo coordinates to query the service for a legislator. FurryBear abstracts much of that process.

Quick start

Let's use Google Maps to find the legislators that correspond to the address "2130 Fulton Street, San Francisco, CA 94117."

$googleMaps = new \FurryBear\Geocode\Provider\GoogleMaps();
$fb->legislators_locate->via($googleMaps)->getByAddress($address);

First, we create an instance of the geocode provider, in this case Google Maps. Next, we register it with the legislators_locate resource and call the getByAddress($address) method.

Available Geocode Providers

  1. Google Maps (FurryBear\Geocode\Provider\GoogleMaps). Its constructor takes a boolean that determines whether the request is made using http or https. By default, the request is made without SSL.
  2. Bing Maps (FurryBear\Geocode\Provider\BingMaps). Its constructor takes two arguments. The first one is the required API key. The second one (optional), determines whether the request is made using http or https. By default, the request is made without SSL.
  3. OpenStreetMap (FurryBear\Geocode\Provider\OpenStreetMap).

Chaining Geocode Providers

Due to provider term restrictions, availability, etc, you may want to have multiple providers specified. That technique has the advantage that if one of the providers is not available, then the others in the chain will take over.

$bingMaps = new \FurryBear\Geocode\Provider\BingMaps('api_key_here');
$googleMaps = new \FurryBear\Geocode\Provider\GoogleMaps();
$chain = new FurryBear\Geocode\Provider\Chain(array($bingMaps, $googleMaps));

$fb->legislators_locate->via($chain)->getByAddress($address);

In this example, if Bing Maps for some reason does not return the coordinates, the task of geocoding will move to Google Maps. Thus you have a better chance of success.

Geocode Providers Terms of Use

This is a disclaimer. Make sure you read the terms of use for those providers before you use them. They have different requirements regarding how their service should be used.

Clone this wiki locally