คลิกหมุดที่เราปัก แล้วแสดงเส้นทาง

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา คลิกหมุดที่เราปัก แล้วแสดงเส้นทาง

คลิกหมุดที่เราปัก แล้วแสดงเส้นทาง
พี่ครับคือผม ทำโปรเจกเกียว กะปั้ทน้ำมันอ่ะ ครับ อยาก ถามพี่ว่า ผมมี map ที่ผม ปักหมุดไวอยู่แล้ว ถ้าผมต้องการ คลิกที่หมุด ที่ผมปักไวแล้วให้มันแสดงเส้นจากพิกัดแล้วเอง ไปยังปลายทางที่เราคลิก หมุดนั้น ครับ ต้อง ทำยังไงครับ  ผมมีcode  ให้พี่ดูด้วยครับ ยังไงรบกวนช่วย ให้หน่อยนะครับ  แล้วต้องไปเพิ่มตรงไหนยังไงครับ 

 ขอบคุณล่วงหน้าครับพี่ num

<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
 <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAt9V7-L8nBdCREaqDMDx0xBQuvtYmYw8_mCk5u1Mm1Kx-fDn-uBTwq5REXD_rGnieamLAw1CPXU_M4w" type="text/javascript" charset="utf-8"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
<link href="../boilerplate.css" rel="stylesheet" type="text/css">
<link href="../find.php" rel="stylesheet" type="text/css">
<link href="../stylle.css" rel="stylesheet" type="text/css">
<!-- 
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
 
Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build 
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<body background="12.png"
<script src="../respond.min.js"></script>
</head>
<center><h1> Pump&nbsp;: Search </h1></center>
</head>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAt9V7-L8nBdCREaqDMDx0xBQuvtYmYw8_mCk5u1Mm1Kx-fDn-uBTwq5REXD_rGnieamLAw1CPXU_M4w" type="text/javascript" charset="utf-8"></script>
<meta charset="utf-8">
<body>
 
<form name="form1" method="post" action="index2.php">
  <input type="submit" name="button" id="button" value="ย้อนหลัง">
</form>
<br/>
<div class="gridContainer clearfix">
  <div id="LayoutDiv1">
  <?
$conn=mysql_connect("localhost","root","root");
if(!empty($conn))
{
mysql_select_db("gisdb");
}else{
echo"";
  }
 
   mysql_db_query("gisdb","SET NAMES UTF8");
 
 $rs1 = mysql_query("select * from province");
 $row1 = mysql_fetch_array($rs1);   
 $prov_id = $row1["prov_id"];
 $prov_name = $row1["prov_name"];
 $prov_lat = $row1["prov_lat"];
 $prov_lon = $row1["prov_lon"];   
   echo $prov_lat;
   echo $prov_lon;
   echo $prov_name; 
 
 
?>
 
<center><div id="map" style="width:400px; height:400px"></div></center>
 
 
<script type="text/javascript">
 
//<![CDATA[
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(<? echo $prov_lat;?>,<? echo $prov_lon;?>), 9);
 
 
 
 
// เรียกใช้คุณสมบัติ ระบุตำแหน่ง ของ html 5 ถ้ามี
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var pos = new GGM.LatLng(position.coords.latitude,position.coords.longitude);
 
var infowindow = new GGM.InfoWindow({
map: map,
position: pos,
content:"ผมเอง"
 
 
 
               
               
                    });                   
var my_Point = infowindow.getPosition();  // หาตำแหน่งของตัว marker เมื่อกดลากแล้วปล่อย
map.panTo(my_Point);  // ให้แผนที่แสดงไปที่ตัว marker
$("#lat_value").val(my_Point.lat());  // เอาค่า latitude ตัว marker แสดงใน textbox id=lat_value
$("#lon_value").val(my_Point.lng()); // เอาค่า longitude ตัว marker แสดงใน textbox id=lon_value 
$("#zoom_value").val(map.getZoom()); // เอาขนาด zoom ของแผนที่แสดงใน textbox id=zoom_value
map.setCenter(pos);
},function() {
// คำสั่งทำงาน ถ้า ระบบระบุตำแหน่ง geolocation ผิดพลาด หรือไม่ทำงาน
});
}else{
// คำสั่งทำงาน ถ้า บราวเซอร์ ไม่สนับสนุน ระบุตำแหน่ง
}
}
 
 
// Creates a marker whose info window displays the given number
function createMarker(point, number)
{
var marker = new GMarker(point);
// Show this markers index in the info window when it is clicked
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
title:"คลิกลากเพื่อหาตำแหน่งจุดที่ต้องการ!" // แสดง title เมื่อเอาเมาส์มาอยู่เหนือ
};
 
 
GEvent.addListener(map,"click", function(overlay,latlng) {
if (overlay) {
return;
}
 
var tileCoordinate = new GPoint();
var tilePoint = new GPoint();
var currentProjection = G_NORMAL_MAP.getProjection();
 
tilePoint = currentProjection.fromLatLngToPixel(latlng, map.getZoom());
tileCoordinate.x = Math.floor(tilePoint.x / 256);
tileCoordinate.y = Math.floor(tilePoint.y / 256);
var myHtml = "Latitude: " + latlng.lat() + "<br/>Longitude: " + latlng.lng() + 
"<br/>The Tile Coordinate is:<br/> x: " + tileCoordinate.x + 
"<br/> y: " + tileCoordinate.y + "<br/> at zoom level " + map.getZoom(); 
map.openInfoWindow(latlng, myHtml);
});
</script>
<?
$rs1 = mysql_query("select * from pin where pin_name LIKE '%PETRONAS%' ");
while($row1 = mysql_fetch_array($rs1))
$pin_name = $row1["pin_name"];
$building_lat = $row1["pin_lat"];
$building_lon = $row1["pin_lon"];
 
 
$pic = $row1["pic"];
$brand = $row1["brand"];
 
 
echo"<script>";
echo "var point = new GLatLng(" . $building_lat. "," . $building_lon. "); ";
echo "var marker = createMarker(point, '" .$pin_name."<img src=img/$pic>'); ";
echo "map.addOverlay(marker); ";
echo " ";
 
echo"</script>";
 
}
 
?>
<center>
 
 </p>
 
<form name="form1" method="post" action="findPETRONAS.php">
  <input type="submit" name="button10" id="button10" value="ปั้ม PETRONAS" />
</form>
<form name="form2" method="post" action="findBANGCHAK.php">
  <input type="submit" name="button3" id="button3" value="ปั้ม BANGCHAK" />
</form>
<form name="form3" method="post" action="findLPG.php">
  <input type="submit" name="button5" id="button5" value="ปั้ม LPG " />
</form>
<form name="form5" method="post" action="findCOSMO.php">
  <input type="submit" name="button7" id="button7" value="ปั้ม COSMO" />
</form>
<form name="form6" method="post" action="findCALTEX.php">
  <input type="submit" name="button4" id="button4" value="ปั้ม CALTEX" />
</form>
<form name="form7" method="post" action="findSUSCO.php">
  <input type="submit" name="button12" id="button12" value="ปั้ม SUSCO" />
</form>
<form name="form8" method="post" action="findESSO.php">
  <input type="submit" name="button6" id="button6" value="ปั้ม ESSO" />
</form>
<form name="form13" method="post" action="findNGV.php">
  <input type="submit" name="button2" id="button2" value="ปั้ม NGV" />
</form>
<form name="form4" method="post" action="findShell.php">
  <input type="submit" name="button11" id="button11" value="ปั้ม Shell" />
</form>
  <form name="form9" method="post" action="findPTT.php">
    <input type="submit" name="button" id="button" value="ปั้ม PTT" />
  </form>
  <form name="form10" method="post" action="findJET.php">
    <input type="submit" name="button8" id="button8" value="ปั้ม JET" />
  </form>
  <form name="form11" method="post" action="findTPI.php">
    <input type="submit" name="button13" id="button13" value="ปั้ม TPI" />
  </form>
  <form name="form12" method="post" action="findMP.php">
    <input type="submit" name="button9" id="button9" value="ปั้ม MP" />
  </form>
  <br/>  
  
  </center>
  <center><div id=footer data-role="footer" class="ui-bar-b">
    <h4><marquee width="270">
      
      design By : ทัตพงศ์ คำวงวาลย์
    </marquee></marquee>
  
</h4>
  </div>
</center>
  </div>
</div>
</body>
</html>
 



Lingaom2329@windowslive.com 171.100.152.xxx 15-10-2014 16:32:41

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
การใช้งานที่ซับซ้อนต้องประยุกต์อย่างเดียว ไม่สามารถแนะนำได้

ลองดูเกี่ยวกับ google map ทั้งหมดได้ที่นี้

https://www.ninenik.com/google_search.php?tags=google map


ninenik 1.46.209.xxx 15-10-2014






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ