|
 |
|
ส่งค่าตัวแปรจาก php ไป javascript ของ Google map ไม่ได้ |
|
 |
|
|
 |
 |
|
คือ ไม่สามารถ ส่งค่าตัวแปร $start กะ $end ไปใช้ในฟังก์ชัน calcRoute() ในจาวาสคริป เพื่อที่จะใช้กำหนดเป็นจุดเริ่มต้น กะปลายทางอ่ะคะ alert ออกมาดูก้แสดงค่านะคะ แต่พอใช้ใน ฟังก์ชัน calcRoute() ก้ไม่ทำงานค่ะ ช่วยทีนะคะ T^T
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Travel - Report</title>
<style type="text/css">
html { height: 100% }
body {
height:100%;
margin:0;padding:0;
}
/* css กำหนดความกว้าง ความสูงของแผนที่ */
#map_canvas {
width:660px;
height:660px;
margin: 5px 10px 5px 10px;
}
</style>
</head>
<body onload="initialize()">
<?
include("include/connect.inc");
$start = $_POST["start"];
$end = $_POST["end"];
$distance = $_POST["totalDistance"];
$duration = $_POST["totalDuration"];
$mode = $_POST["mode"];
$product_oil = $_POST["product"];
$price_oil = $_POST["txtHint"];
$energyuse = $_POST["energy"];
echo '<script type="text/javascript">';
echo "var start = '$start';";
echo "var end = '$end';";
echo '</script>';
if($price_oil != "" and $energyuse != "" and $distance != "" and $product_oil != "NGV")
{
$amountOil = $distance/$energyuse;
$costperkm = $price_oil/$energyuse;
$totalCost = ($price_oil/$energyuse)*$distance;
}
if($product_oil == "NGV")
{
$energyuse = $energyuse/0.9;
$amountOil = $distance/$energyuse;
$costperkm = $price_oil/$energyuse;
$totalCost = ($price_oil/$energyuse)*$distance;
}
?>
<div id="result">
<span>สถานที่เริ่มต้น :</span><span><? echo $start ?></span><br />
<span>สถานที่ปลายทาง :</span><span><? echo $end ?></span><br />
<span>ระยะทางรวม :</span><span><? echo $distance?></span><br />
<span>ใช้เวลา :</span><span><? echo $duration ?></span><br />
<span>ค่าเชื้อเพลิง :</span><span><? echo $price_oil ?> บาท/ลิตร ( <? echo $product_oil ?> )</span><br />
<span>ปริมาณน้ำมัน :</span><span><? echo $amountOil ?> ลิตร</span><br />
<span>ค่าใช้จ่ายต่อกิโลเมตร :</span><span><? echo $costperkm ?> บาท/กม.</span><br />
<span>ค่าใช้จ่ายโดยรวมทั้งหมด :</span><span><? echo $totalCost ?> บาท</span><br />
</div>
<div id="map_canvas"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.8&sensor=false&language=th"></script>
<script type="text/javascript">
var rendererOptions = {
draggable: true
};
var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);;
var directionsService = new google.maps.DirectionsService();
var map;
var center = new google.maps.LatLng(13.761728449950002,100.6527900695800);
function initialize() {
var myOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: center
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("directionsPanel"));
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
computeTotalDistance(directionsDisplay.directions);
});
calcRoute();
}
function calcRoute() {
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
</script>
</body>
</html>
Tag : PHP, JavaScript

|
ประวัติการแก้ไข 2012-04-11 23:21:43
|
 |
 |
 |
 |
Date :
2012-04-11 23:20:29 |
By :
CzPlussiiz |
View :
1540 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
origin: <?=$start;?>,
แบบนี้หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-04-17 08:09:52 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|