title: Cakephp google map getting latittude,longitude and formated address
body: <p>I have <strong>ContactusController.php</strong> function as :</p>
  
  <pre><code>&lt;?php
  App::uses('GeocodeLib', 'Tools.Lib');
  class ContactusController extends AppController
  {
      public function beforeFilter()
      {
  parent::beforeFilter();
  $this-&gt;Auth-&gt;allow('main', 'step2');
  
  }
  
  
  
  public $name = 'Contactus';
  
  
  
  public $components = array('RequestHandler', 'Email', 'Session'); 
  
  public $helpers = array('Js','Html','Form', 'Tools.GoogleMapV3'); 
  
  
  
  
  
  public function main() {
  
  
  
      if ($this-&gt;request-&gt;is('post')) {
  
  
  
          $this-&gt;Contactus-&gt;set($this-&gt;data);
  
  
  
            if ($this-&gt;Contactus-&gt;validates()) {
  
  
  
              $settings = array('min_accuracy'=&gt;GeocodeLib::ACC_SUBLOC);
  
  
  
              $this-&gt;Geocode = new GeocodeLib();
  
              $this-&gt;Geocode-&gt;setOptions(array('host'=&gt;'us')); //optional - you can set it to your country's top level domain.
  
              if ($this-&gt;Geocode-&gt;geocode($this-&gt;data['Contactus']['address1']. " " .$this-&gt;data['Contactus']['address2'], $settings)) {
  
                  $result = $this-&gt;Geocode-&gt;getResult();
  
  
  
                   /*debug($result);*/
  
  
  
                  $options = array(
  
                      'lat' =&gt; $result['lat'],
  
                      'lng' =&gt; $result['lng'],
  
                      'content' =&gt; 'Testing',
  
                      'draggable' =&gt; TRUE,
  
  
  
                  );
  
  
  
              }
  
                  /*
  
                  $this-&gt;Email-&gt;to = array("sales@ichiban.com.my", "clement@ichiban.com.my");
  
                  $this-&gt;Email-&gt;subject = 'Please contact ' . $this-&gt;data['Contactus']['name'];
  
                  $this-&gt;Email-&gt;from = "websys@ichiban.com.my"; 
  
                  $this-&gt;Email-&gt;bcc = "yienbin@nixser.com";
  
                  $this-&gt;Email-&gt;replyTo = $this-&gt;data['Contactus']['email'];
  
                  //25, Jalan Ceria 5, Taman Nusa Indah, Johor
  
                  $this-&gt;Email-&gt;send("Name: " . $this-&gt;data['Contactus']['name'] . "\n" .
  
                                                "Phone: " . $this-&gt;data['Contactus']['phone'] . "\n" .
  
                                                "Fax: " . $this-&gt;data['Contactus']['fax'] . "\n" .
  
                                                "Address: " . $this-&gt;data['Contactus']['address'] . "\n" .
  
                                                "Email: " . $this-&gt;data['Contactus']['email'] . "\n" . 
  
                                                "Detail: " . $this-&gt;data['Contactus']['detail'] . "\n");
  
  
  
                  $this-&gt;Session-&gt;setFlash('Sent', 'message', array('class' =&gt; 'success1'));
  
                  */
                  $this-&gt;request-&gt;data['Customer'] = $this-&gt;request-&gt;data['Contactus'];
                  $this-&gt;loadModel('Customer');
                  pr($this-&gt;request-&gt;data);
                  $this-&gt;Customer-&gt;save($this-&gt;request-&gt;data);
  
            }
  
  
  
          $this-&gt;set(array(
  
              'options' =&gt; $options
  
              ));
  
  
  
      }
  
      $customerStatuses = $this-&gt;Contactus-&gt;CustomerStatus-&gt;find('list');
      $enquiryTypes = $this-&gt;Contactus-&gt;EnquiryType-&gt;find('list');
      $this-&gt;set(compact('customerStatuses', 'enquiryTypes'));    
      $this-&gt;layout = 'popup';
  
  
  
  }
  
  
  
  public function step2() {
  
  
  
  
  
      $this-&gt;layout = 'popup';
  
  
  
  }
  
  
  
       }
  
      ?&gt;
  </code></pre>
  
  <p>and this is <strong>main.ctp</strong> function </p>
  
  <pre><code>        &lt;div class="row"&gt;
  
          &lt;div class="span10 breakline"&gt;
              &lt;h1 class="headtitle"&gt;Your Contact Details&lt;/h1&gt;
              &lt;h2&gt;Please confirm your address and provide your name, phone number and email address&lt;/h2&gt;
  
              &lt;?php 
                  echo $this-&gt;Form-&gt;create('Contactus');
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('full_name', array( 'label' =&gt; 'Full Name' )) . "\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('company_name', array( 'label' =&gt; 'Company Name' )) ."\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('phone', array( 'label' =&gt; 'Phone Number' )) ."\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('email', array( 'label' =&gt; 'Email Address' )) ."\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('address1', array( 'label' =&gt; 'Address Line 1')) ."\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('address2', array( 'label' =&gt; 'Address Line 2')) ."\n";
                  echo "&lt;/div&gt;\n";
  
  
                  echo  $this-&gt;Form-&gt;input('formated_address', array( 'label' =&gt;false,'type'=&gt;'hidden'));
                  echo  $this-&gt;Form-&gt;input('lat', array( 'label' =&gt;false,'type'=&gt;'hidden'));
                  echo  $this-&gt;Form-&gt;input('lng', array( 'label' =&gt;false,'type'=&gt;'hidden'));
  
  
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('contact_by', array( 'label' =&gt; 'Contact Me By','type'=&gt;'select','options'=&gt;array('Email'=&gt;'Email','Telephone'=&gt;'Telephone'))) ."\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('enquiry_type_id', array('type'=&gt;'select', 'label' =&gt; 'Type Of Enquiry')) ."\n";
                  echo "&lt;/div&gt;\n";
  
                  echo "&lt;div class='control-group'&gt;\n";
                  echo "". $this-&gt;Form-&gt;input('customer_status_id', array('type'=&gt;'select', 'label' =&gt; 'Customer Type')) ."\n";
                  echo "&lt;/div&gt;\n";
  
  
                  //echo $this-&gt;Form-&gt;end('Next', array('class' =&gt; 'btn btn-primary'));
                  echo $this-&gt;Form-&gt;end(__('Next', array('class' =&gt; 'btn btn-primary')));
              ?&gt;
  
          &lt;/div&gt;
  
          &lt;div class="span10 breakline"&gt;
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  
      &lt;h2&gt;Please drag the map to find your installation location, and place the pin on your roof&lt;/h2&gt;
  
      &lt;?php echo $this-&gt;Session-&gt;flash(); 
      echo $this-&gt;Html-&gt;script($this-&gt;GoogleMapV3-&gt;apiUrl());
      $options2 = array(
                  'zoom'=&gt;6,
                  'type'=&gt;'R',
                  'autoCenter' =&gt; true,
                  'div' =&gt; array('id'=&gt;'mapCanvas'),
                  'map' =&gt; array('navOptions'=&gt;array('style'=&gt;'SMALL'), 'typeOptions' =&gt; array('style'=&gt;'HORIZONTAL_BAR', 'pos'=&gt;'RIGHT_TOP'))
              );
              //debug($options2);
      ?&gt;
  
      &lt;?php
      if ($this-&gt;request-&gt;is('post')) {
  
              // tip: use it inside a for loop for multiple markers
              //echo $this-&gt;GoogleMapV3-&gt;map($options2);
  
  
              $js = "
                  var geocoder = new google.maps.Geocoder();
  
                  function geocodePosition(pos) {
                    geocoder.geocode({
                      latLng: pos
                    }, function(responses) {
                      if (responses &amp;&amp; responses.length &gt; 0) {
                        updateMarkerAddress(responses[0].formatted_address);
                      } else {
                        updateMarkerAddress('Cannot determine address at this location.');
                      }
                    });
                  }
  
                  function updateMarkerStatus(str) {
                    document.getElementById('markerStatus').innerHTML = str;
                  }
  
                  function updateMarkerPosition(latLng) {
                    document.getElementById('info').innerHTML = [
                      latLng.lat(),
                      latLng.lng()
                    ].join(', ');
                  }
  
                  function updateMarkerAddress(str) {
                    document.getElementById('address').innerHTML = str;
                  }
  
                  function initialize() {
                    var latLng = new google.maps.LatLng(" . $options['lat'] . ", " . $options['lng'] . ");
                    var map = new google.maps.Map(document.getElementById('mapCanvas'), {
                      zoom: 17,
                      center: latLng,
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                    });
                    var marker = new google.maps.Marker({
                      position: latLng,
                      title: 'Point A',
                      map: map,
                      draggable: true
                    });
  
                    // Update current position info.
                    updateMarkerPosition(latLng);
                    geocodePosition(latLng);
  
                    // Add dragging event listeners.
                    google.maps.event.addListener(marker, 'dragstart', function() {
                      updateMarkerAddress('Dragging...');
                    });
  
                    google.maps.event.addListener(marker, 'drag', function() {
                      updateMarkerStatus('Dragging...');
                      updateMarkerPosition(marker.getPosition());
                    });
  
                    google.maps.event.addListener(marker, 'dragend', function() {
                      updateMarkerStatus('Drag ended');
                      geocodePosition(marker.getPosition());
                    });
                  }
  
                  // Onload handler to fire off the app.
                  google.maps.event.addDomListener(window, 'load', initialize);
  
              ";
  
              //$this-&gt;GoogleMapV3-&gt;addMarker($options);
  
              //$this-&gt;GoogleMapV3-&gt;addCustom($js);
  
              // print js
              echo $this-&gt;Html-&gt;scriptBlock($js);
  
          }
  
      ?&gt;
      &lt;div id="mapCanvas"&gt;&lt;/div&gt;
  
      &lt;div id="infoPanel"&gt;
  
          &lt;b&gt;Marker status:&lt;/b&gt;
          &lt;div id="markerStatus"&gt;&lt;i&gt;Click and drag the marker.&lt;/i&gt;&lt;/div&gt;
  
          &lt;b&gt;Current position:&lt;/b&gt;
          &lt;div id="info"&gt;&lt;/div&gt;
  
          &lt;b&gt;Closest matching address:&lt;/b&gt;
          &lt;div id="address"&gt;&lt;/div&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>I want to get the <strong></strong> and  to inser into the field <strong>"formated_address"</strong>,
   <strong>"lat"</strong> and <strong>"long"</strong></p>
  
  <p>Please help me out I am not able to do that.</p>
  
  <p>When I debug I am getting this :</p>
  
  <pre><code>    Array
      (
  [Contactus] =&gt; Array
      (
          [full_name] =&gt; yein Bin
          [company_name] =&gt; Microsoft
          [phone] =&gt; +6012345678
          [email] =&gt;someting@gmail.com
          [address1] =&gt; 25, Jalan Ceria 5
          [address2] =&gt; Taman Nusa Indah, Johor
          [formated_address] =&gt; 
          [lat] =&gt; 
          [lng] =&gt; 
          [contact_by] =&gt; Email
          [enquiry_type_id] =&gt; 1
          [customer_status_id] =&gt; 1
      )
  
  [Customer] =&gt; Array
      (
          [full_name] =&gt; yein Bin
          [company_name] =&gt; Microsoft
          [phone] =&gt; +6012345678
          [email] =&gt;someting@gmail.com
          [address1] =&gt; 25, Jalan Ceria 5
          [address2] =&gt; Taman Nusa Indah, Johor
          [formated_address] =&gt; 
          [lat] =&gt; 
          [lng] =&gt; 
          [contact_by] =&gt; Email
          [enquiry_type_id] =&gt; 1
          [customer_status_id] =&gt; 1
      )
  
    )
  </code></pre>
  
  <p>someone please help me out</p>