How do I render a map?

Created by Brian Armstrong on on 2009-11-13
Keywords:
map render
Last updated by:
Brian Armstrong on on 2009-12-03

SUMMARY

The map rendering is handled by the GeoCode_Result class. It uses its own internal 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 extension 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

Place the following code into your view

* Yahoo Map Example *

<div id="map_canvas"></div>
<?php
// $result is a GeoCode_Result object from a Yahoo Driver
$options = array(
    'mapType' => 'YAHOO_MAP_REG'
);
$result->renderMap('map_canvas', $options);
?>

* Google Map Example *

<div id="map_canvas"></div>
<?php
// $result is a GeoCode_Result object from a Google Driver
$options = array(
    'mapTypeId' => 'ROADMAP',
    'zoom' => 13
);
$result->renderMap('map_canvas', $options);
?>

* Google Map with Yahoo Result *

<div id="map_canvas"></div>
<?php
// $result is a GeoCode_Result object from a Yahoo Driver
$options = array(
    'mapTypeId' => 'ROADMAP',
    'zoom' => 13
);
$result->renderMap('map_canvas', $options, 'google');
?>

If you would like to render multiple points to a given map, please see https://answers.launchpad.net/yiigeo/+faq/845 for more information on how this can be accomplished.