Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

ElGoorf edited this page · 9 revisions
Clone this wiki locally

Zend_Form_Element_Googlemap

Version 1.0.0.000.0.a.0

Abstract

I needed to create a form with one of the inputs being the user's approximate location. I figured the best long-term solution would be to create it as an extension of the Zend_Form_Element class. Decided to share it for the benefit of fellow Zend users. It may not be perfect, but I don't claim to be either, and its free so you aren't allowed to complain :).

Thanks to Bittarman (freenode #zftalk) for tech help :)

Files

/Zend/Form/Element/Googlemap.php

Contains all the functions to create the form element.

/Zend/View/Helper/formGooglemap.php

Generates the HTML/JS to show the map on the form.

Functions (examples below)

setAPIKey(string $key) - Most people wont need a key since Version 3. See Google Maps Documentation for info.

setZoom(int $z) - Initial zoom level for the map (default zoom = 5)

setDimensions(string|int $w, string|int mixed $h) - Size of the map. If integers are given, they're be treated as pixel values. If a string is given with "%", they'll be treated as percentages

setCenter(string|float $x[, float $y]) - Initial focal coordinates of the map. A single Google LatLng string can be given, or individual latitude and longitude values.

setMode(mode) - Not fully implemented. This is used to set the mode of the input:

  • SINGLE - User can enter a single location

Examples

1

$map = new Zend_Form_Element_Googlemap('map');
$map->setLabel("Please mark your approximate location") // Just like for any other form element.
    ->setZoom(4) //Set the initial zoom level for the map
    ->setCenter("55.801281,-3.735352") // Can be a Google LatLng string or two individual coordinates (see below)
    ->setDimensions(400, 400); // Map space is a 400 by 400 pixels square; can be percentages (see below)
$this->addElement($map);

2

$map = new Zend_Form_Element_Googlemap('map');
$map->setLabel("Please mark your approximate location")
    ->setCenter(55.801281,-3.735352) // Coordinates given as 2 individual floats (latitude and longitude)
    ->setDimensions(50%, 50%); // Map will occupy a quarter of its container.
$this->addElement($map);
Something went wrong with that request. Please try again.