Lets have a look at one diginights location-detail page: There is a Google Map on the bottom of the page which displays the locations' accurate position. The database-table therfore holds three columns: The two coordinate values for lattitude an longitude and the zoom factor.
Our problem was the missing userfriendly admin interface, so i wrote a little class for this purpose which uses the Google Maps API to select a coordinate by double clicking the map. Additionaly an adress can be looked up which uses Google's Geocoder class internally.
Feel free to download all necessary files here: GMapsCoordPicker.zip. The zip-archive contains 4 files:
GMapsCoordPicker.class.js
Put this file in your project's javascript directory (/web/js), it handls client side logic.
GoogleMapsHelper.php
Put this file in your project's helper dir (/lib/helper). It supplies a helper function google_maps_coord_picker(). The following example shows the usage in a symfony template:
This helper includes the Google Maps API, thus an API key has to be generated and set up in the application configuration (/apps/[appname]/config/app.yml):
_google_maps_coordinate_picker.php
To simply integrate in the admin generator, we need a tremplate that includes the helper showed above and displays the map. You have to replace the parameters passed to google_maps_coord_picker() with the input field ids of your form. Note that symfony uses object_input_tag() for its form elements which builds unconvenional form-field-ids.
generator.yml
This file displays the integration of _google_maps_coordinate_picker.php in the admin generator.