google maps api tutorial geocoder example class in php

google maps api tutorial geocoder example class in php with controller

google-maps-api-tutorial-geocoder-example-class.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>google maps api tutorial geocoder example class in php with controller</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="google maps api tutorial geocoder example class in php with controller">
  <meta name="keywords" content="php, example, code, class, function, google maps, google geocoder maps, google maps class, controller">
  <meta name="description" content="google maps api tutorial geocoder example class in php with controller">
  <style>
   h2, h3{background:orange; color:#000089;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h3{ padding:2px; margin:2px; font-size:19px;}
   p{ padding:3px; margin:3px;}
   body{ background:#FFFFFA;}
   div{ margin:1px; padding:1px;}
  </style>
 </head>
 <body>
  <h2>google maps api tutorial geocoder example class in php with controller</h2>
  <pre>
   <?php
    /*
     -----------------------------------------------------------------------------------------
     let us make and explain the class
     
     where
     
     1. location, width and height can be changed dynamically by instance
     2. APIKey is the key can be found from http://code.google.com/apis/maps/signup.html
      * in production server you must have to provide an api key
       unless otherwise maps will not be shown.
     -----------------------------------------------------------------------------------------
    */
    class GoogleGeocoderMaps
    {
     var $APIKey = "abcdefg";
     var $Location = "Dhaka, BD";
     var $Width = 710;
     var $Height = 350;
   
     function SetLocation($Location)
     {
      $this->Location = $Location;
     }
     function SetWidth($Width)
     {
      $this->Width = $Width;
     }
     function SetHeight($Height)
     {
      $this->Height = $Height;
     }
     function DisplayMaps()
     {
     ?>
     <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=<?php echo $this->APIKey; ?>" type="text/javascript"></script> 
     <script type="text/javascript"> 
      var JobLocationInGoogleGeocoderMaps = '<?php echo $this->Location; ?>';
      if (GBrowserIsCompatible()) 
      {
       var geocoder = new GClientGeocoder();
       geocoder.getLocations(JobLocationInGoogleGeocoderMaps, function (locations) 
       {         
        if (locations.Placemark) 
        {
         var north = locations.Placemark[0].ExtendedData.LatLonBox.north;
         var south = locations.Placemark[0].ExtendedData.LatLonBox.south;
         var east  = locations.Placemark[0].ExtendedData.LatLonBox.east;
         var west  = locations.Placemark[0].ExtendedData.LatLonBox.west;
         
         var bounds = new GLatLngBounds(new GLatLng(south, west), new GLatLng(north, east));
         var map = new GMap2(document.getElementById("GoogleMapDisplay"));
         map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
         //map.addControl(new GSmallMapControl());
         map.addControl(new GLargeMapControl());
         map.addControl(new GMapTypeControl());
         map.addOverlay(new GMarker(bounds.getCenter()));
        }
       });
      }
      GUnload();
     </script> 
     <div id="GoogleMapDisplay" style="width:<?php echo $this->Width; ?>px; height:<?php echo $this->Height; ?>px; background-repeat:no-repeat; background-position:center;"></div> 
     <?php                
     }
    }
    /*
     --------------------------------------------------------------------------------------
     now we want to fire up the class to make object to display google geocoder maps
     --------------------------------------------------------------------------------------
    */
    $location = "dhaka,BD";
    /*
     ------------------------------------------------------------------------------------------
     you can dynamically change the value of $location to get the desire google geocoder maps
     ------------------------------------------------------------------------------------------
    */
    echo "<h3>parameter supplied to GoogleGeocoderMaps class to make the maps with controller</h3>";
    print "<p>$"."location = ".$location."</p>";
    $Map = new GoogleGeocoderMaps();
    $Map->SetWidth(500);
    $Map->SetHeight(250);
    $Map->SetLocation($location);
    $Map->DisplayMaps();
   ?>
  </pre>
 </body>
</html>

google maps api tutorial geocoder example class in php with controller - output in the browser

No comments:

Post a Comment

leave your comments here..