JacobHsu
9/5/2013 - 7:08 AM

map.php

<?php

error_reporting(E_ALL^E_NOTICE^E_WARNING); //關閉PHP的所有錯誤提示

//參數接收
// $user_id = $_POST['user_id'];

//測試資料 
 $user_id = 17;

 //header("Content-type: application/json");
 require_once("../db.config.php");
?>

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--中文顯示-->
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/map.js"></script>
</head>

<body onload="initialize()">

	       	<?php	 
	       	         $dbh = new PDO("mysql:host=" . db('hostname') . ";dbname=" . db('dbname'), db('username'), db('password'), 
				      array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") ); 
				     
				     $arrLatLng =array();
				     $arrScenicName =array();

				      $locations_db_json='';
                   
				      $sql_loc = "SELECT * FROM yourLocTable  WHERE user_id=$user_id";
				      foreach ($dbh->query($sql_loc) as $row) {
                          $LatLng =  "(".$row['lat'].",".$row['lng'].")";  
                          $item_id =$row['id']; 
                          $ScenicName  =$row['name']; 
                          $phpecho = $phpecho.$row['id'].$LatLng; 

                          $locations_db_json.='{';
		                  $locations_db_json.= 'latlng : new google.maps.LatLng';
						  $locations_db_json.= $LatLng;//'(25.0336148,120.56480220000003)';
						  $locations_db_json.=',';	
						  $locations_db_json.= 'info :';	
						  $locations_db_json.= '"'.$markerName.'"'; ;//'"hello"';	
						  $locations_db_json.= '},';
        
                                     
                      }	      

      //                 $json_db ='{';
	     //              $json_db.= 'latlng : new google.maps.LatLng';
					 //  $json_db.= '(25.0336148,120.56480220000003)';
					 //  $json_db.=',';	
					 //  $json_db.= 'info :';	
					 //  $json_db.= '"hello"';	
					 //  $json_db.= '},';
					 //  $json_db.='{
						// 		latlng : new google.maps.LatLng(25.0336148,  121.56480220000003),
						// 	    info : "world"
						// },';
	
		     ?>

			<script type="text/javascript">
                <?php $str = " debugStr from php=";?>
			     var debugStr = '<?php echo $str.$phpecho;?>'; //php輸出字串到js要加單引 //對應寫入html的程式在map.js

				var locations = [
                    <?php echo $locations_db_json; ?>
				];


			</script>	

<div id="map_canvas" style="width: 100%;height:300px;"></div>
<span> debug value : </span> <span id="debug"></span> 
</body>
</html>