Advertisement
Guest User

parsing html, geocoding addresses and put multiple markers

a guest
Jan 18th, 2012
288
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.30 KB | None
  1. <?php
  2. $site=@$_POST['name'];
  3. if (!isset($site)) {$site="e95";}
  4.  
  5. if($site=="e95"){$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1";}
  6. elseif($site=="e98"){$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=5";}
  7. elseif($site=="dd"){$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=9";}
  8.  
  9. ?>
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11.  
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  14. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  15. <style type="text/css">
  16.       html { height: 100% }
  17.       body { height: 100%; margin: 0; padding: 0 }
  18.       #map_canvas { height: 100%; top:0px}
  19.      
  20.       #menu {
  21.         position: fixed;
  22.     _position:absolute;
  23.     _top:expression(eval(document.body.scrollTop));
  24.     left:80px;
  25.     top:0px;
  26.     background-color: #ffffff }
  27.     </style>
  28.  
  29.     <!--
  30.     <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBk8OFey58Ql2epl2c5d8OR9fkn8HU-gh0&sensor=false">
  31.     -->
  32.    
  33.     <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
  34.     </script>
  35. </head>
  36. <?php
  37.  
  38. //this lib kicks donkeys AKA rocks
  39. //http://simplehtmldom.sourceforge.net/
  40. include_once('simple_html_dom.php');
  41. //////////////////////////////////////
  42.  
  43. //$html= file_get_html('http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1');
  44. $html= file_get_html($site);
  45.  
  46. $v = $html->find('table[id=tresult]');
  47.  
  48.  
  49.  
  50.     foreach($v[0]->find('script,a') as $e) {
  51.         $e->outertext= '';
  52.         }
  53.        
  54. //        foreach($v[0]->find('img')as $e){
  55. //      $e->outertext=;
  56.        
  57. //        }
  58.     foreach ($v[0]->find('span') as $e){
  59.         $e->outertext= "<span>".$e->plaintext."</span>" ;
  60.         }
  61.        
  62.  
  63.     foreach($v[0]->find('div[class=tooltip_small]') as $e) {
  64.         $e->style= '';
  65.         }
  66.        
  67.    
  68.  
  69.  
  70.       //echo $v[0];
  71.  
  72.     $w = $v[0]->find('tr');
  73.    
  74.  
  75. ?>
  76.  
  77. <body onload="initialize()">
  78.     <div id="map_canvas" style="width:100%; height:100%"></div>
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. <?php  
  86. $i=0;
  87.  
  88.      
  89.     foreach ($w as $e){
  90.         $adress= $e->find('span');
  91.         $adreses= explode(",",$adress[0]->plaintext);
  92.        
  93.         $allPrices=$e->find('td[class=price]');
  94.        
  95.         $nosaukums=$e->find('img');
  96.        
  97.         //$nosaukums=$nosaukums[0]->alt;
  98.        
  99.        
  100.        
  101.         foreach ($adreses as $adrese){
  102.             $adrese=str_replace("Adreses","",$adrese);
  103.            
  104.             $allStations[$i][0]=trim($adrese);
  105.             $allStations[$i][1]=trim($allPrices[0]->plaintext);
  106.             $allStations[$i][1]=str_replace("-","'nav'",$allStations[$i][1]);
  107.             $allStations[$i][2]=trim($allPrices[1]->plaintext);
  108.             $allStations[$i][2]=str_replace("-","'nav'",$allStations[$i][2]);
  109.             $allStations[$i][3]=trim($allPrices[2]->plaintext);
  110.             $allStations[$i][3]=str_replace("-","'nav'",$allStations[$i][3]);
  111.             $allStations[$i][4]=trim($nosaukums[0]->alt);
  112.             //echo trim($adrese)." ".trim($allPrices[0]->plaintext)." ".trim($allPrices[1]->plaintext). " ".trim($allPrices[2]->plaintext)."</br> \n";
  113.             $i++;
  114.         }
  115.         //echo $adreses." ".$allPrices[0]." ".$allPrices[1]. " ".$allPrices[2]."</br>";
  116.     //echo $e."\n";
  117.     }
  118. ?>
  119.  
  120.  
  121. <script type="text/javascript">
  122.   var geocoder;
  123.   var map;
  124.   var marker = new Array();
  125.   var infowindow = null;
  126.  
  127.   function initialize() {
  128.     geocoder = new google.maps.Geocoder();
  129.     var latlng = new google.maps.LatLng(56.397, 23.644);
  130.     var myOptions = {
  131.       zoom: 11,
  132.       //center: latlng,
  133.       mapTypeId: google.maps.MapTypeId.ROADMAP
  134.     }
  135.     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  136.     <?php
  137.    
  138.     $i=0;
  139.     array_shift($allStations);
  140.     foreach ($allStations as $adrese) {
  141.         if ($i<10)  {
  142.             echo "codeAddress(\"".$adrese[0].", Rīga, Latvija\",$i,$adrese[1],$adrese[2],$adrese[3],'$adrese[4]');\n";
  143.             }
  144.         $i++;
  145.     }
  146.     ?>
  147.   }
  148.  
  149.  
  150.  
  151.  
  152.   function codeAddress(address,markerNr,e95,e98,dd,nosaukums) {  
  153.  
  154.    
  155.     geocoder.geocode( { 'address': address}, function(results, status) {
  156.    
  157.       if (status == google.maps.GeocoderStatus.OK) {
  158.         //var newIcon = MapIconMaker.createMarkerIcon({width: 64, height: 64, primaryColor: "#00ff00"});
  159.        
  160.         map.setCenter(results[0].geometry.location);
  161.             marker = new google.maps.Marker({
  162.           <?php
  163.           //echo "//$site";
  164.           if ($site=="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1"){echo "icon: 'icons/gas95.png',";}
  165.           elseif($site=="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=5"){echo "icon: 'icons/gas98.png',";}
  166.           elseif($site=="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=9"){echo"icon: 'icons/gasdd.png',";}
  167.           else{echo"icon: 'icons/gas95.png',";}
  168.           ?>
  169.        
  170.             map: map,
  171.             position: results[0].geometry.location,
  172.         title: nosaukums+" (" + address + "); 95`ais - " + e95 + " LVL/l; 98`ais - " + e98 + " LVL/l; dīzelis - " + dd + " LVL/l."
  173.         });
  174.        
  175.       } else {
  176.         alert("Geocode was not successful for the following reason: " + status);
  177.       }
  178.     });
  179.   }
  180.    
  181.      
  182.     </script>
  183.    
  184. <div id="menu">
  185. <form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post" name="formasName">
  186.  
  187. <select name="name" onChange="document.forms['formasName'].submit()">
  188. <option>
  189.       select gas type
  190. </option>
  191. <option>
  192.       e95
  193. </option>
  194. <option>
  195.       e98
  196. </option>
  197. <option>
  198.       dd
  199. </option>
  200. </select>
  201. </form>
  202.  </div>
  203.  
  204. </body>
  205.  
  206.  
  207.  
  208. </html>
Advertisement
RAW Paste Data Copied
Advertisement