text: This extension allows you to use a standard interface for GeoCoding APIs. As well as to auto generate a Yahoo or Google map of the GeoCoded location.
  Currently supported APIs are Google, GeoCoder.us, and Yahoo.
  protected/extensions
  Register for an API Key
  Google key:
  Yahoo key:
  See the following code examples:
  Standalone
  Yii::import('application.extensions.geocoder.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
  'components' => array( ... 'geocoder' => array( 'class' => 'application.extensions.geocoder.GeoCoder', 'api_key' => '<your API key>', 'api_driver' => '<your driver>', // 'google' or 'yahoo' ), ... ) $result = Yii::app()->geocoder->query('Las Vegas, NV 89103');
  Summary
  The map rendering is handled by the GeoCode_Result class. It uses its own render functions to generate the maps. It also requires javascript to be enabled.
  Map Types
  The map types that are rendered need to be passed to the view. These are constants as defined by the map supplier. Only include the constant name, do NOT include namespaces, etc.
  Caveats
  It is possible to change the map provider that is used for rendering a specific GeoCode_Result by passing an optional 3rd parameter to the renderMap function with the name of the provider. However, because some map APIs (eg. Yahoo) require an API key to validate access, these maps can only be rendered from a Result derived from their respective driver.
  Because this is using v3 of the Google Maps API, it does not require an API key to access the javascript. Therefore, a google map can be rendered from any Result object. The same can not be said for the other map providers.
  Usage
  Create an empty div in your HTML with the id of "map_canvas", then use the following code:
  Yahoo Map Example
  // $result is a GeoCode_Result object from a Yahoo Driver $result->renderMap('map_canvas', array( 'mapType' => 'YAHOO_MAP_REG' ));
  Google Map Example
  // $result is a GeoCode_Result object from a Google Driver $result->renderMap('map_canvas', array( 'mapTypeId' => 'ROADMAP', 'zoom' => 13 ));
  Note: Some browsers will not render the contents of the canvas and the maps will appear to be hidden. To fix this, add a new CSS entry to main.css that will force the browser to give the canvas a width and height.
  #map_canvas { width: 500px; height: 300px; }
  As of version 1.0.4 it is now possible to render multiple points to the same map. This can be accomplished in two ways: 1) by rendering multiple results to the same container, 2) by manually specifying the lat/lon where the marker is to be placed.
  Example
  // $result is an array of GeoCode_Result objects from a Google Driver $result[0]->renderMap('map_canvas', array( 'mapTypeId' => 'ROADMAP', 'zoom' => 13 )); // Render the second result to the same map // Any options passed to the function will be ignored // since this canvas has already been initialized $result[1]->renderMap('map_canvas'); // Render a point manually to that same canvas // Arguments are in this order because if no canvas is // specified, it defaults to using the last one created $result[0]->renderPoint($my_lat, $my_lon, 'map_canvas');
  Total 3 comments
  when i use the GeoCoder extension with the google driver on the accordion effect of the pogostick extension it crach the browser I think that there is a style coflict
  This is a good extension. It does what it should.
  But maybe some suggestions: I have never used the google api before. It was quite annoying to figure out what constants are valid and where they are documented. Maybe you could point your users to it (in your documentation:).
  I also added some "nice to have" things into the code. First I added a event in the point-view to center my map on a click of the marker:You have all these information alrdy inside the view and I found it quite useful ;)
  I also added a options-variable to the renderPointer-function (maybe not everyone wants the pointer to be clickable or whatever).
  Also a good addition might be the ability to add a InfoWindow into the map. I just copied the renderPoint-function into a new one (the option-array must contain a content-field, which is used for the window):and the view (I found it quite dirty to use "gmap" and "marker" as predefined elements, but you did the same in the point-view (only gmap in there ;) ) and I don't wanted it more complicated just for me ^^):
  maybe you or someone else find these things also useful.
  Thanks for share! is so good!
  Please login to leave your comment.