Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ขอสอบถามเรื่อง GDirection ของ Google Maps API หน่อยครับ



 

ขอสอบถามเรื่อง GDirection ของ Google Maps API หน่อยครับ

 



Topic : 031372



โพสกระทู้ ( 327 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Facebook Hi5



ตอนนี้ผมกำลังทดสอบการทำงานของ GDirection นะครับ แต่ยังทำได้ไม่ตรงกับความต้องการ

โดยในโค๊ดดังกล่าวนี้ จะสามารถกำหนดจุดได้แค่สองจุดเท่านั้นคือ จุด A ถึง จุด B

แต่อยากให้สามารถเพิ่มจุดได้อีก เช่น เพิ่ม C D E...เพราะในบางกรณีจำเป็นต้องบังคับให้ไปในทางอื่น

ซึ่งไม่ใช่ทางลัดในรูปแบบของ Google Maps

หากท่านใดมีความรู้ด้านนี้ช่วยดูให้หน่อยนะครับ

Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=Windows-874"/>
<title>Draggable Directions</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA-ozu9u-kcsavHZaBs2caKBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSK3X8Kdd_K5vZo2hyr7oytsnpGrA"type="text/javascript"></script>
<style type="text/css">
body {font-family: Verdana, Arial, sans serif; font-size: 11px; margin: 2px;}
table.directions th {background-color:#EEEEEE;}
img {color: #000000;}
</style>
<script type="text/javascript">

var map;
var gdir;

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "error", handleErrors);
GEvent.addListener(gdir, "addoverlay", onGDirectionsAddOverlay); // Triggers marker swap, Esa
map.setCenter(new GLatLng(0,0),0); // inital setCenter() added by Esa.

var mapControl = new GMapTypeControl();
map.addControl(mapControl);
map.addControl(new GOverviewMapControl());//คอนโทรคเพิ่มแผนที่ขนาดเล็กแต่ย่อ
map.setUIToDefault() //การเพิ่มคอนโทรลของ Scrollwhell Zoomming ตั้งค่าเริ่มต้นแบบ Gmap เลย
setDirections("6.996385006067268,100.46313643455505", "6.9988981508929475,100.48882126808167", "th");
// api version display added by Esa
document.getElementById("api-v").innerHTML = '2.'+G_API_VERSION;




}
}

function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress,
{ "locale": locale , "getSteps":true});
}

function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}

///////////////////////////////////////////////////////////////////////

/**
* The add-on code for draggable markers
* @author Esa 2008
*/
var newMarkers = [];
var latLngs = [];
var icons = [];

// Note the 'addoverlay' GEvent listener inside initialize() function of the original code (above).
// 'load' event cannot be used

function onGDirectionsAddOverlay(){
// Remove the draggable markers from previous function call.
for (var i=0; i<newMarkers.length; i++){
map.removeOverlay(newMarkers[i]);
}

// Loop through the markers and create draggable copies
for (var i=0; i<=gdir.getNumRoutes(); i++){
var originalMarker = gdir.getMarker(i);
latLngs[i] = originalMarker.getLatLng();
icons[i] = originalMarker.getIcon();
newMarkers[i] = new GMarker(latLngs[i],{icon:icons[i], draggable:true, title:'Draggable'});
map.addOverlay(newMarkers[i]);

// Get the new waypoints from the newMarkers array and call loadFromWaypoints by dragend
GEvent.addListener(newMarkers[i], "dragend", function(){
var points = [];
for (var i=0; i<newMarkers.length; i++){
points[i]= newMarkers[i].getLatLng();
}
gdir.loadFromWaypoints(points);
});

//Bind 'click' event to original markers 'click' event
copyClick(newMarkers[i],originalMarker);

// Now we can remove the original marker safely
map.removeOverlay(originalMarker);
}

function copyClick(newMarker,oldMarker){
GEvent.addListener(newMarker, 'click', function(){
GEvent.trigger(oldMarker,'click');
});
}
}

</script>


</head>
<body onload="initialize()" onunload="GUnload()">

<h2>การหาเส้นทางที่ใกล้ที่สุด</h2>
<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">

<table>

<tr><th align="right">From:&nbsp;</th>

<td><input type="text" size="25" id="fromAddress" name="from"
value="start"/></td>
<th align="right">&nbsp;&nbsp;To:&nbsp;</th>
<td align="right"><input type="text" size="25" id="toAddress" name="to"
value="finish" /></td></tr>

<tr><th>Language:&nbsp;</th>
<td colspan="3"><select id="locale" name="locale">

<option value="th" selected>Thailand</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="ja">Japanese</option>
<option value="es">Spanish</option>
<option value="fi">Finnish</option>
</select>

<input name="submit" type="submit" value="Get Directions!" />

</td></tr>

</table>


</form>

<br/>
<table class="directions">
<tr><th>Formatted Directions</th><th>Map</th></tr>

<tr>
<td valign="top"><div id="directions" style="width: 275px"></div></td>
<td valign="top"><div id="map_canvas" style="width: 900px; height: 550px"></div></td>




</div></td>

</tr>

</table>
</body>
</html>




Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-09-06 23:48:11 By : indysoft View : 3703 Reply : 7
 

 

No. 1

Guest


ตาม ลิ้งนี้เลยครับ http://www.lecturer.eng.chula.ac.th/fsvskk/gglmap2/get-start-gmap-apiv2.html#Google_Maps_mashup
ลองอ่านดูครับภาษาไทยเข้าใจง่ายๆครับ


ติดตามอ่านต่อได้ที่

http://www.thaiems.net
http://forum.thaiems.net
http://it-goo.blogspot.com
http://chita-funnyjoke.blogspot.com






Date : 2009-09-07 10:29:30 By : konlata
 


 

No. 2



โพสกระทู้ ( 327 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Facebook Hi5

ลิงค์ดังกล่าวเป็นพื้นฐานทั่วไปนะครับ ไม่ได้มีสอนเกี่ยวกับ GDirection
Date : 2009-09-07 17:46:43 By : indysoft
 

 

No. 3



โพสกระทู้ ( 327 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Facebook Hi5

ใครพอจะทราบวิธีการเปลี่ยนจากหมุดธรรมดา ให้เป็นภาพที่เรากำหนดเองมั้ยครับ

อย่างในโค้ตตัวอย่างนั้น จะเป็นหมุด A B ธรรมดา อยากเป็นเป็นหมุดซึ่งเป็นภาพที่ผมทำมาเองเป็น .png อะครับ
Date : 2009-09-28 22:37:01 By : indysoft
 


 

No. 4



โพสกระทู้ ( 1,322 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ลองดูเข้าไปที่นี้ดูนะครับ

Tutorial แบบบ้านๆ ตอนที่ 1 – Basic Google Maps API

credit : เรียนรู้ google map api จาก select2web.com


Date : 2009-09-29 09:28:47 By : pokultra
 


 

No. 5



โพสกระทู้ ( 1,463 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

//นอก loop
var newHouse = new GIcon(G_DEFAULT_ICON);
newHouse.iconSize = new GSize(35,35);
newHouse.image = "images/house.png";

//ใน loop
icons[i] = originalMarker.getIcon();
เปลี่ยนเป็น
icons[i] = newHouse;
ครับ
Date : 2009-09-29 12:09:16 By : num
 


 

No. 6

Guest


ตอนนี้ผมกำลังทดสอบการทำงานของ GDirection นะครับ แต่ยังทำได้ไม่ตรงกับความต้องการ

โดยในโค๊ดดังกล่าวนี้ จะสามารถกำหนดจุดได้แค่สองจุดเท่านั้นคือ จุด A ถึง จุด B

แต่อยากให้สามารถเพิ่มจุดได้อีก เช่น เพิ่ม C D E...เพราะในบางกรณีจำเป็นต้องบังคับให้ไปในทางอื่น

ซึ่งไม่ใช่ทางลัดในรูปแบบของ Google Maps

หากท่านใดมีความรู้ด้านนี้ช่วยดูให้หน่อยนะครับ


ผมก็มีปัญหานี้เหมือนกับคุณ Indysoft ครับ แล้วต้องทำอย่างไงครับ
Date : 2010-03-01 14:01:02 By : raby
 


 

No. 7



โพสกระทู้ ( 327 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Facebook Hi5

ปัญหานี้ ผมแก้ไขได้แล้วนะ โดยการเพิ่มจุดนั่นหละครับ เมื่อเราเพิ่มจุดแล้ว ก็ให้มันหาเส้นใหม่

ก็จะได้เส้นใหม่ โดยจะอ้างให้ผ่านจุดที่ต้องการได้ครับ เดี๋ยวเอาไว้จะทำเป็นเอกสารสอนให้นะ

รอให้สอบเสร็จก่อนครับ ช่วงนี้เร่งให้จบ ไม่ค่อยได้ว่างเลย
Date : 2010-03-02 01:02:57 By : indysoft
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอสอบถามเรื่อง GDirection ของ Google Maps API หน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่