How do I install and use YiiGeo?

Created by Brian Armstrong on on 2009-11-13
Keywords:
use howto install
Last updated by:
Brian Armstrong on on 2009-11-13

INSTALLATION

Extract the contents of the archive to 'protected/extensions/'. Rename the default directory (eg: 'yiigeo-1.0.1/') to whatever you want the component named in your application. This directory will be referred to as '<extdir>' in this tutorial.

USAGE

Register for an API Key with a support GeoCoder provider
Google registration: http://code.google.com/apis/maps/signup.html
Yahoo registration: http://developer.yahoo.com/maps/rest/V1/geocode.html

There are two ways to use the Yii GeoCoder Extension. The first is as an imported standalone object, the second is as an application component.

*Standalone*

<?php
Yii::import('application.extensions.<extdir>.GeoCoder');
$geocode = new GeoCoder;
$geocode->init();
$geocode->setApiKey('<your API key>'); // As of 1.0.2
$geocode->setDriver('<your driver>'); // 'google' or 'yahoo'
$result = $geocode->query('Las Vegas, NV 89103');

*Application Component*

STEP 1: Update your application config

'components' => array(
  ...
    'geocoder' => array(
       'class' => 'application.extensions.<extdir>.GeoCoder',
       'api_key' => '<your API key>',
       'api_driver' => '<your driver>', // 'google' or 'yahoo'
     ),
  ...
)

STEP 2: Using the component

<?php
$result = Yii::app()->geocoder->query('Las Vegas, NV 89103');