PHPackages                             krixer/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. krixer/google-map-form-type-bundle

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

krixer/google-map-form-type-bundle
==================================

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

v1.3(5y ago)9118.9k↓44.7%11[2 PRs](https://github.com/krixer/OhGoogleMapFormTypeBundle/pulls)MITPHPPHP ^5.4 || ^7.0 || ^8.0

Since Jan 16Pushed 2y ago2 watchersCompare

[ Source](https://github.com/krixer/OhGoogleMapFormTypeBundle)[ Packagist](https://packagist.org/packages/krixer/google-map-form-type-bundle)[ Docs](https://github.com/krixer/OhGoogleMapFormTypeBundle)[ RSS](/packages/krixer-google-map-form-type-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)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 3 and 4. Use composer to install:

```
composer require krixer/google-map-form-type-bundle

```

Register the bundle in your `config/bundles.php`:

```
// config/bundles.php
return [
    // ...
    Oh\GoogleMapFormTypeBundle\OhGoogleMapFormTypeBundle::class => ['all' => true],
];
```

Create options file in `config/packages` directory

```
# config/packages/oh_google_map_form_type.yaml
oh_google_map_form_type:
    api_key: "%google_maps_api_key%"
```

Usage
-----

[](#usage)

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

```
$builder->add('latlng', GoogleMapType::class);

```

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

```
// Your model eg, src/My/Location/Entity/MyLocation.php
use Oh\GoogleMapFormTypeBundle\Traits\LocationTrait;

class MyLocation
{
    // ... include your lat and lng fields here using LocationTrait
    use LocationTrait;

}

```

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_themes:
        # 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'           => HiddenType::class,  // the types to render the lat and lng fields as
	'addr_type'      => TextType::class,  // the type to render the address field
	'attr'           => ['class' => 'form-group'],
	'search_enabled' => true,
	'options'        => [], // the options for both the fields
	'lat_options'    => [], // the options for just the lat field
	'lng_options'    => [], // the options for just the lng field
	'addr_options'   => [], // the options for just the addr field
	'lat_name'       => 'latitude',   // the name of the lat field
	'lng_name'       => 'longitude',   // the name of the lng field
	'addr_name'      => 'address',  // the name of the addr field (optional)
	'error_bubbling' => false,
	'map_width'      => '100%',  // the width of the map
	'map_height'     => '300px', // the height of the map
	'default_lat'    => 41.390205,    // the starting position on the map
	'default_lng'    => 2.154007, // 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.
- Hector Escriche (krixer) as contributor.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~876 days

Total

4

Last Release

1876d ago

PHP version history (3 changes)1.0.0PHP &gt;=5.3.2

v1.1PHP ^5.4 || ^7.0

v1.3PHP ^5.4 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a717eb89d079f23fbab1e2d27dd800c7419e5ceb7d944162617d40468b95af39?d=identicon)[krixer](/maintainers/krixer)

---

Top Contributors

[![ollietb](https://avatars.githubusercontent.com/u/342090?v=4)](https://github.com/ollietb "ollietb (49 commits)")[![krixer](https://avatars.githubusercontent.com/u/1197537?v=4)](https://github.com/krixer "krixer (18 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)")[![jorrit](https://avatars.githubusercontent.com/u/521449?v=4)](https://github.com/jorrit "jorrit (3 commits)")[![nicodemuz](https://avatars.githubusercontent.com/u/1620454?v=4)](https://github.com/nicodemuz "nicodemuz (3 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)")[![sujayjaju](https://avatars.githubusercontent.com/u/1681240?v=4)](https://github.com/sujayjaju "sujayjaju (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)")[![AndiKeiser](https://avatars.githubusercontent.com/u/9332971?v=4)](https://github.com/AndiKeiser "AndiKeiser (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)")[![toooni](https://avatars.githubusercontent.com/u/241080?v=4)](https://github.com/toooni "toooni (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)")

---

Tags

symfonyformgoogle maps

### Embed Badge

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

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

###  Alternatives

[pugx/autocompleter-bundle

Add an autocomplete type to forms

93861.6k3](/packages/pugx-autocompleter-bundle)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3376.9M38](/packages/a2lix-translation-form-bundle)[artgris/filemanager-bundle

FileManager is a simple Multilingual File Manager Bundle for Symfony

182420.8k9](/packages/artgris-filemanager-bundle)[norberttech/aceeditor-bundle

Bundle that integrate excellent JavaScript ace editor into Symfony Form.

28310.8k](/packages/norberttech-aceeditor-bundle)[beelab/recaptcha2-bundle

Provide Google Recaptcha2 form type

55455.1k1](/packages/beelab-recaptcha2-bundle)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

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