title: match zip code or address from php page to google map
body: <p>I have a PHP page in which address of some person fecth from database table.</p>
  
  <p>Like:  </p>
  
  <pre><code>Person name  address  zip     MAP
  
  MR. xyz      city1    1234    click
  MR. abc      city2    1234    click
  MR. dfe      city3    1244    click
  MR. rrr      city4    1284    click
  </code></pre>
  
  <p>If admin clicks on <strong>click button</strong> of <strong>Mr. abc</strong> then google map should be open with <strong>address</strong> or <strong>zip</strong> of <strong>MR. abc</strong> and google location should be open on google map of <strong>MR. abc</strong></p>
  
  <p>I don't have any idea how to do this? Please give some suggestion. </p>
  
  <p>Now I found a code:</p>
  
  <pre><code> &lt;?php
  include("connection.php");
  
   function geocode($address){
  
     // url encode the address
    $address = urlencode($address);
  
    // google map geocode api url
    $url = "http://maps.google.com/maps/api/geocode/json?address={$address}";
  
    // get the json response
    $resp_json = file_get_contents($url);
  
    // decode the json
    $resp = json_decode($resp_json, true);
  
      // response status will be 'OK', if able to geocode given address 
     if($resp['status']=='OK'){
  
      // get the important data
      $lati = $resp['results'][0]['geometry']['location']['lat'];
      $longi = $resp['results'][0]['geometry']['location']['lng'];
      $formatted_address = $resp['results'][0]['formatted_address'];
  
      // verify if data is complete
      if($lati &amp;&amp; $longi &amp;&amp; $formatted_address){
  
          // put the data in the array
          $data_arr = array();            
  
          array_push(
              $data_arr, 
                  $lati, 
                  $longi, 
                  $formatted_address
              );
  
          return $data_arr;
  
      }else{
          return false;
      }
  
      }else{
      return false;
    }
   }
  
  
    if($_REQUEST){
  
     // get latitude, longitude and formatted address
     $data_arr = geocode($_REQUEST['address']);
  
      // if able to geocode the address
     if($data_arr){
  
      $latitude = $data_arr[0];
      $longitude = $data_arr[1];
      $formatted_address = $data_arr[2];
  
     ?&gt;
  
      &lt;!-- google map will be shown here --&gt;
     &lt;div id="gmap_canvas"&gt;Loading map...&lt;/div&gt;
     &lt;div id='map-label'&gt;Map shows approximate location.&lt;/div&gt;
  
     &lt;!-- JavaScript to show google map --&gt;
      &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js"&gt;&lt;/script&gt;    
      &lt;script type="text/javascript"&gt;
      function init_map() {
          var myOptions = {
              zoom: 14,
              center: new google.maps.LatLng(&lt;?php echo $latitude; ?&gt;, &lt;?php echo $longitude; ?&gt;),
              mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
          marker = new google.maps.Marker({
              map: map,
              position: new google.maps.LatLng(&lt;?php echo $latitude; ?&gt;, &lt;?php echo $longitude; ?&gt;)
          });
          infowindow = new google.maps.InfoWindow({
              content: "&lt;?php echo $formatted_address; ?&gt;"
          });
          google.maps.event.addListener(marker, "click", function () {
              infowindow.open(map, marker);
          });
          infowindow.open(map, marker);
      }
      google.maps.event.addDomListener(window, 'load', init_map);
      &lt;/script&gt;
  
      &lt;?php
  
      // if unable to geocode the address
      }else{
      echo "No map found.";
     }
     }
  
     ?&gt;
  
       But it gave an ERROR:  **Map shows approximate location.** 
  </code></pre>
  
  <p>Is it right code or not?   </p>