PHPackages                             bastien-wink/google-map-form-type-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bastien-wink/google-map-form-type-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

bastien-wink/google-map-form-type-bundle
========================================

Set latitude, longitude and address values on a form using Google Maps

1.1(8y ago)0110MITPHPPHP &gt;=5.3.2

Since Jan 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/bastien-wink/OhGoogleMapFormTypeBundle)[ Packagist](https://packagist.org/packages/bastien-wink/google-map-form-type-bundle)[ Docs](https://github.com/ollieLtd/OhGoogleMapFormTypeBundle)[ RSS](/packages/bastien-wink-google-map-form-type-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

OhGoogleMapFormTypeBundle
=========================

[](#ohgooglemapformtypebundle)

Set latitude and longitude values on a form using Google Maps. The map includes a search field and a current location link. When a pin is placed or dragged on the map, the latitude and longitude fields are updated.

Installation
------------

[](#installation)

This bundle is compatible with Symfony 2.1. Add the following to your `composer.json`:

```
"oh/google-map-form-type-bundle": "dev-master"

```

Register the bundle in your `app/AppKernel.php`:

```
// app/AppKernel.php
public function registerBundles()
    {
        $bundles = array(
            new Oh\GoogleMapFormTypeBundle\OhGoogleMapFormTypeBundle(),
            // ...
```

You might need to change a couple of options if you are trying to use Symfony 2.0

Add OhGoogleMapFormTypeBundle to assetic

```
# app/config/config.yml
# Assetic Configuration
assetic:
    bundles:        [ 'OhGoogleMapFormTypeBundle' ]
```

Usage
-----

[](#usage)

This bundle contains a new FormType called GoogleMapType which can be used in your forms like so:

```
$builder->add('latlng', 'oh_google_maps');

```

On your model you will have to process the latitude and longitude array

```
// Your model eg, src/My/Location/Entity/MyLocation.php
use Symfony\Component\Validator\Constraints as Assert;
use Oh\GoogleMapFormTypeBundle\Validator\Constraints as OhAssert;

class MyLocation
{
    // ... include your lat and lng fields here

    public function setLatLng($latlng)
    {
        $this->setLat($latlng['lat']);
        $this->setLng($latlng['lng']);
        return $this;
    }

    /**
     * @Assert\NotBlank()
     * @OhAssert\LatLng()
     */
    public function getLatLng()
    {
        return array('lat'=>$this->getLat(),'lng'=>$this->getLng());
    }

}

```

Include the twig template for the layout. It's generally a good idea to overwrite the form template in your own twig template

```
# your config.yml
twig:
    form:
        resources:
            # This uses the default - you can put your own one here
            - 'OhGoogleMapFormTypeBundle:Form:fields.html.twig'

```

If you are intending to override some of the elements in the template then you can do so by extending the default `google_maps.html.twig`. This example adds a callback to the javascript when a new map position is selected.

```
{# your template which is inluded in the config.yml (above)
   eg src/My/Location/Resources/views/Form/fields.html.twig #}
{% extends "OhGoogleMapFormTypeBundle:Form:google_maps.html.twig" %}
{% block oh_google_maps_callback %}

			var oh_google_maps_callback = function(location, gmap){
                // logs to the console your new latitude
				console.log('Your new latitude is: '+location.lat());
			}

{% endblock %}

```

Options
-------

[](#options)

There are a number of options, mostly self-explanatory

```
array(
	'type'           => 'text',  // the types to render the lat and lng fields as
	'options'        => array(), // the options for both the fields
	'lat_options'    => array(), // the options for just the lat field
	'lng_options'    => array(), // the options for just the lng field
	'addr_options'   => array(), // the options for just the addr field
	'lat_name'       => 'lat',   // the name of the lat field
	'lng_name'       => 'lng',   // the name of the lng field
	'addr_name'      => 'addr',  // the name of the addr field (optional)
	'map_width'      => '100%',  // the width of the map
	'map_height'     => '300px', // the height of the map
	'default_lat'    => 51.5,    // the starting position on the map
	'default_lng'    => -0.1245, // the starting position on the map
	'include_jquery' => false,   // jquery needs to be included above the field (ie not at the bottom of the page)
	'include_gmaps_js'=>true     // is this the best place to include the google maps javascript?
)

```

Screenshots
-----------

[](#screenshots)

[Default form](https://www.dropbox.com/s/pvoihkkq74imnk3/location-form-1.png)[Current position](https://www.dropbox.com/s/uhf7fk3mx35j137/location-form-current.png)[Search locations](https://www.dropbox.com/s/qdft149ggyfil0p/location-form-search.png)[LatLng validation](https://www.dropbox.com/s/k0xqku5q2gv2nlo/location-form-validation.png)

Known problems
--------------

[](#known-problems)

Because the form type template includes javascript, there's not yet a way to bunch it all together at the very bottom of the page, so it is included at the bottom of the field. This means that jquery and the javascript plugin in Resources/public/js needs to be included before the field. I'm not sure of a way around this, but I think it's going to be addressed in a later version of the form framework.

Credits
-------

[](#credits)

- Ollie Harridge (ollietb) as main author.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1258 days

Total

2

Last Release

3243d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/184754ad1daf16a9e122ab2bbd84ab404e58b4a50cf788909fdf56400044d3c7?d=identicon)[bastien-wink](/maintainers/bastien-wink)

---

Top Contributors

[![ollietb](https://avatars.githubusercontent.com/u/342090?v=4)](https://github.com/ollietb "ollietb (42 commits)")[![oebabaluba](https://avatars.githubusercontent.com/u/3095916?v=4)](https://github.com/oebabaluba "oebabaluba (4 commits)")[![webbertakken](https://avatars.githubusercontent.com/u/20756439?v=4)](https://github.com/webbertakken "webbertakken (4 commits)")[![l3l0](https://avatars.githubusercontent.com/u/209405?v=4)](https://github.com/l3l0 "l3l0 (3 commits)")[![bastien-wink](https://avatars.githubusercontent.com/u/7903123?v=4)](https://github.com/bastien-wink "bastien-wink (2 commits)")[![rmasters](https://avatars.githubusercontent.com/u/34284?v=4)](https://github.com/rmasters "rmasters (2 commits)")[![ner0tic](https://avatars.githubusercontent.com/u/161227?v=4)](https://github.com/ner0tic "ner0tic (2 commits)")[![fabstei](https://avatars.githubusercontent.com/u/1098434?v=4)](https://github.com/fabstei "fabstei (2 commits)")[![xmon](https://avatars.githubusercontent.com/u/4361296?v=4)](https://github.com/xmon "xmon (1 commits)")[![dnna](https://avatars.githubusercontent.com/u/1296821?v=4)](https://github.com/dnna "dnna (1 commits)")[![JokubasR](https://avatars.githubusercontent.com/u/3471628?v=4)](https://github.com/JokubasR "JokubasR (1 commits)")[![scollado](https://avatars.githubusercontent.com/u/712999?v=4)](https://github.com/scollado "scollado (1 commits)")[![stmichael](https://avatars.githubusercontent.com/u/540306?v=4)](https://github.com/stmichael "stmichael (1 commits)")[![Warxcell](https://avatars.githubusercontent.com/u/3340882?v=4)](https://github.com/Warxcell "Warxcell (1 commits)")[![wlzch](https://avatars.githubusercontent.com/u/977245?v=4)](https://github.com/wlzch "wlzch (1 commits)")[![aitboudad](https://avatars.githubusercontent.com/u/1753742?v=4)](https://github.com/aitboudad "aitboudad (1 commits)")

---

Tags

symfonyformgoogle maps

### Embed Badge

![Health badge](/badges/bastien-wink-google-map-form-type-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/bastien-wink-google-map-form-type-bundle/health.svg)](https://phpackages.com/packages/bastien-wink-google-map-form-type-bundle)
```

###  Alternatives

[kris/laravel-form-builder

Laravel form builder - symfony like

1.7k2.2M45](/packages/kris-laravel-form-builder)[winzou/state-machine-bundle

Bundle for the very lightweight yet powerful PHP state machine

34010.4M15](/packages/winzou-state-machine-bundle)[pentatrion/vite-bundle

Vite integration for your Symfony app

2725.3M13](/packages/pentatrion-vite-bundle)[norberttech/aceeditor-bundle

Bundle that integrate excellent JavaScript ace editor into Symfony Form.

28310.8k](/packages/norberttech-aceeditor-bundle)[ekreative/uuid-extra-bundle

Paramconverter, Normalizer and Form Type for Ramsey Uuid

18168.6k](/packages/ekreative-uuid-extra-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
