diabliyo

google_maps.php

Feb 14th, 2012
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2. #
  3. # M.S.I. Angel Cantu Jauregui
  4. # angel.cantu [a] sie-group.net
  5. # http://www.sie-group.net
  6. #
  7.  
  8. include( "modulos/modulos.php" );
  9. define( API_GOOGLEMAPS, "HASH_API_GOOGLE" );
  10. define( GOOGLEMAPS_SERVER, "maps.google.com" ); # servidor de apis
  11. if( API_GOOGLEMAPS )
  12.     {
  13.     define( GOOGLEMAPS_STATICMAP, "/maps/api/staticmap?key=". API_GOOGLEMAPS ); # mapas estaticos
  14.     define( GOOGLEMAPS_GEOCODEJSON, "/maps/api/geocode/json?key=". API_GOOGLEMAPS. "&" ); # mapas geocode por json
  15.     define( GOOGLEMAPS_GEOCODEXML, "/maps/api/geocode/xml?key=". API_GOOGLEMAPS. "&" ); # mapas geocode por xml
  16.     define( GOOGLEMAPS_GEOCODEJS, "/maps/api/js?key=". API_GOOGLEMAPS. "&" ); # mapas geocode por javascript
  17.     }
  18. else
  19.     {
  20.     define( GOOGLEMAPS_STATICMAP, "/maps/api/staticmap?" ); # mapas estaticos
  21.     define( GOOGLEMAPS_GEOCODEJSON, "/maps/api/geocode/json?" ); # mapas geocode por json
  22.     define( GOOGLEMAPS_GEOCODEXML, "/maps/api/geocode/xml?" ); # mapas geocode por xml
  23.     define( GOOGLEMAPS_GEOCODEJS, "/maps/api/js?" ); # mapas geocode por javascript
  24.     }
  25. define( GOOGLEMAPS_SENSOR, "false" ); # sensor google maps false o true
  26.  
  27. if( $_GET["place"] || $_GET["data"] ) # si hay lugar a identificar
  28.     {
  29.     if( !$_GET["data"] &&  $_GET["place"] ) # si no es latitud y longitud
  30.         {
  31.         $args= 'address='. urlencode($_GET["place"]). '&sensor='. GOOGLEMAPS_SENSOR;
  32.         $datos= array( 'GET', GOOGLEMAPS_GEOCODEXML.$args   );
  33.         $r= socket_iodata( GOOGLEMAPS_SERVER, $datos, 80 );
  34.         $xml= simplexml_load_string($r[1]);
  35.         unset($r);
  36.         if( !is_object($xml) )
  37.             echo 'Error XML.';
  38.         else
  39.             {
  40.             $latitud= $xml->result->geometry->location->lat;
  41.             $longitud= $xml->result->geometry->location->lng;
  42.             }
  43.         }
  44.     else if( $_GET["data"] && !$_GET["place"] )# entonces si hay latitude y longitud
  45.         {
  46.         if( strstr($_GET["data"], ",") )
  47.             {
  48.             $x= explode( ",", $_GET["data"]);
  49.             $latitud= $x[0];
  50.             $longitud= $x[1];
  51.             }
  52.         else
  53.             echo 'Error data...';
  54.         }
  55.        
  56.     if( $latitud && $longitud)
  57.         {
  58.         $dimencion= '280x280'; # dimencion de la imagen
  59.         $args= 'zoom=15&size='. $dimencion. '&maptype=roadmap&markers=color:blue|label:S|'. $latitud. ','. $longitud. '&sensor='. GOOGLEMAPS_SENSOR;
  60.         $datos= array( 'GET', GOOGLEMAPS_STATICMAP.$args );
  61.         $r= socket_iodata( GOOGLEMAPS_SERVER, $datos, 80);
  62.  
  63.         header_imagen( "image/png" );
  64.         echo $r[1];
  65.         }
  66.     else
  67.         echo 'Error Latitud y Longitud';
  68.     }
  69. else
  70.     echo 'Error Args...';
  71. ?>
Add Comment
Please, Sign In to add comment