PHP code example of daa / addressable-bundle

1. Go to this page and download the library: Download daa/addressable-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daa / addressable-bundle example snippets


return [
    ...
    Addressable\Bundle\AddressableBundle::class => ['all' => true]
]

new Addressable\Bundle\AddressableBundle(),

    namespace Your\Project\Entity;

    use Addressable\Bundle\Model\AddressableInterface;
    use Addressable\Bundle\Model\Traits\ORM\AddressableTrait;
    # for optional email, tel, fax fields also         use AddressableTrait;
        use ContactableTrait;
        
        /**
         * @ORM\Column(type="text")
         */
        protected $yourOtherField;
        
        ...
    }

use Addressable\Bundle\Form\Type\AddressMapType;
use Addressable\Bundle\Form\Type\ContactDetailsType; # optional email, tel, fax

// if you are using standard symfony form type
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('address', AddressMapType::class, array(
            'google_api_key' => 'yourKeyHere'
        ))
    ...
}

// if you are using Sonata Admin
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->with('Location')
            ->add('address', AddressMapType::class, array(
                'google_api_key' => 'yourKeyHere'
            ))
        ->end()
        ...
}

/**
 * if you are doing it directly in a controller Action
 * 
 * @Route("/", name="homepage")
 * @Template("@App/page.html.twig")
 */
public function indexAction(Request $request)
{
    $entity = new AddressableEntity();
    $form = $this->createForm(AddressMapType::class, $entity, array(
        'google_api_key' => 'yourKeyHere'
    ));
    
    /* or alternatively when using the nested/related versions:
    $form = $this->createFormBuilder($entity)
        ->add('address', AddressMapType::class, array(
            'google_api_key' => 'yourKeyHere'
        ))
        ->add('contactDetails', ContactDetailsType::class)
        ->getForm();
    */

    // replace this example code with whatever you need
    return [
        'form' => $form->createView(),
    ];
}


->add(
    'address',
     AddressMapType::class,
     array(
        'google_api_key' => 'yourKeyHere',
         '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_current_position_action' => true, // whether to include the set current position button
         'street_number_field' => array(
             'name' => 'streetNumber',
             'type' => 'text',
             'options' => array(
                 '_field' => array(
             'name' => 'country',
             'type' => 'text',
             'options' => array(
                 '2',
             'type' => 'text',
             'options' => array(
                 '