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

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

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

Set latitude and longitude values on a form using Google Maps or an array to display a trip

1.0.0(12y ago)023MITPHPPHP &gt;=5.3.2

Since Jan 16Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

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

[](#ohgooglemapformtypebundle)

This is a fork from ollietb's bundle. Thanks to him.

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.

I added the feature to set an array of 2 pairs of latitudes and longitudes to display a single trip betwwen two points.

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

[](#installation)

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

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

```

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

```
// app/AppKernel.php
public function registerBundles()
    {
        $bundles = array(
            new FloFrad\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
	'lat_name'       => 'lat',   // the name of the lat field
	'lng_name'       => 'lng',   // the name of the lng field
	'map_width'      => 300,     // the width of the map
	'map_height'     => 300,     // 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

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.7% 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

Unknown

Total

1

Last Release

4506d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b9842c847a61d25a9b1e98d82c124c03a8577bbe75a00f77c300e5b5325f22a?d=identicon)[flofrad](/maintainers/flofrad)

---

Top Contributors

[![ollietb](https://avatars.githubusercontent.com/u/342090?v=4)](https://github.com/ollietb "ollietb (37 commits)")[![FloFrad](https://avatars.githubusercontent.com/u/697367?v=4)](https://github.com/FloFrad "FloFrad (6 commits)")[![l3l0](https://avatars.githubusercontent.com/u/209405?v=4)](https://github.com/l3l0 "l3l0 (3 commits)")[![rmasters](https://avatars.githubusercontent.com/u/34284?v=4)](https://github.com/rmasters "rmasters (2 commits)")[![fabstei](https://avatars.githubusercontent.com/u/1098434?v=4)](https://github.com/fabstei "fabstei (2 commits)")[![ner0tic](https://avatars.githubusercontent.com/u/161227?v=4)](https://github.com/ner0tic "ner0tic (2 commits)")[![aitboudad](https://avatars.githubusercontent.com/u/1753742?v=4)](https://github.com/aitboudad "aitboudad (1 commits)")[![wlzch](https://avatars.githubusercontent.com/u/977245?v=4)](https://github.com/wlzch "wlzch (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)")

---

Tags

symfonyformgoogle maps

### Embed Badge

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

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

###  Alternatives

[winzou/state-machine-bundle

Bundle for the very lightweight yet powerful PHP state machine

34010.4M15](/packages/winzou-state-machine-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)[oh/google-map-form-type-bundle

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

15167.2k](/packages/oh-google-map-form-type-bundle)[arbermustafa/filament-locationpickr-field

Location picker field for Filament Php using Google Maps

1539.0k](/packages/arbermustafa-filament-locationpickr-field)

PHPackages © 2026

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