[ js ] google map 與路徑規劃相關問題

看板Ajax作者 (sexyboy)時間16年前 (2009/09/12 23:35), 編輯推噓3(3014)
留言17則, 3人參與, 最新討論串1/1
各位前輩好,小弟最近在寫google map的相關網頁程式,遇到一些問題,希望能有前輩 相助。 關於google mpa路經規劃API,其Maps API Directions Illustrated google的demo網站為:http://snipurl.com/rs0kc 語法主要使用GDirections.load() 小弟嘗試更改其程式碼將setDirections("San Francisco", "Mountain View", "en_US"); 改為setDirections("板橋火車站", "台北火車站", "zh-TW"); 跑不出結果,小弟以為google map不提供路徑規劃的中文輸入 後來我另外的想法是利用geocoding查詢兩地的經緯度 directions.load("from: 25.001169323785923, 121.45265579223633 to: 25.03341222278933, 121.56749725341797"); 直接輸入經緯度是可以的,但是我修改過的程式,變數最後一直顯示NaN,想請各位大大 幫忙解惑 ------------------------------以下為程式碼---------------------------------- <script type="text/javascript"> var map = null; var geocoder = null; var marker; var directionsPanel; var directions; var geoPoint=new GLatLng; var i=0; var geoPoint1=new GLatLng; var geoPoint2=new GLatLng; function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); //加入地圖縮放工具 map.addControl(new GMapTypeControl()); //加入地圖切換的工具 map.addMapType(G_PHYSICAL_MAP); //加入地形圖 map.setCenter(new GLatLng(25.001689, 121.460809), 8); //設定台灣為中心點 geocoder = new GClientGeocoder(); directionsPanel = document.getElementById("my_textual_div"); directions = new GDirections(map, directionsPanel); } } function createMarker(point,title,html) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml( html, { maxContent: html, maxTitle: title} ); }); return marker; } function showAddress(address1,address2) { geoPoint1=make(address1); geoPoint2=make(address2); alert(geoPoint); directions.load("from: " +geoPoint1 + "to: " + geoPoint2, "zh-TW"); } function make(test) { var testPoint=new GLatLng; if (geocoder) { geocoder.getLatLng( test, function(point) { if (!point) { alert(test + " not found"); } else { if(marker) //移除上一個點 { //map.removeOverlay(marker); } map.setCenter(point, 13); var title = "地址"; //line(point,i); marker = createMarker(point,title,test); map.addOverlay(marker); marker.openInfoWindowHtml(test,{maxContent: test,maxTitle: title}); testPoint=point; alert(testPoint); } } ); } return testPoint; } </script> ----------------------------------程式碼結束--------------------------------- 測試網頁連結:http://192.192.155.86/geocoding1.htm 小弟剛接觸JavaScript不久,希望各位大大能幫忙,小弟程度不好,如果問題很簡單, 請指點迷津,小弟先說聲抱歉~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.169.10.152

09/14 03:55, , 1F
GDirections.load()的第二個參數好像是要用json來傳送吧
09/14 03:55, 1F

09/14 03:58, , 2F
{ "locale": "zh_TW" } 試看看這樣吧~~
09/14 03:58, 2F

09/14 04:02, , 3F
ps. 其實我也沒用過~只是看了一好文件好像是這樣@@a
09/14 04:02, 3F

09/14 10:18, , 4F
樓上大大~我改成
09/14 10:18, 4F

09/14 10:18, , 5F
directions.load("from: 銝緍憭批飛 to: 啣貗怨뮊
09/14 10:18, 5F

09/14 10:20, , 6F
directions.load("from: 世新大學 to: 台北火車站",
09/14 10:20, 6F

09/14 10:20, , 7F
{ "locale": "zh_TW" });
09/14 10:20, 7F

09/14 10:20, , 8F
依然不行...
09/14 10:20, 8F

09/14 20:53, , 9F
剛剛去申請了key來試了一下~程式沒有問題,是地址的問題
09/14 20:53, 9F

09/14 20:54, , 10F
我用"from: 世新大學 to: 台北火車站"也是不行的
09/14 20:54, 10F

09/14 20:55, , 11F
但是用完整地址卻可以,忽然想到加了個Taiwan給他吧
09/14 20:55, 11F

09/14 20:57, , 12F

09/14 20:58, , 13F
我直接把Taiwan加在送出的程式裡了
09/14 20:58, 13F

09/14 20:59, , 14F
這樣直接輸入"世新大學"跟"台北火車站"也找的到
09/14 20:59, 14F

09/15 07:51, , 15F
感謝大大^^~
09/15 07:51, 15F

11/27 10:28, , 16F
請guancheng大大 放上你測試的完整code
11/27 10:28, 16F

11/27 10:28, , 17F
因為我也遇到一樣的問題
11/27 10:28, 17F
文章代碼(AID): #1Agx_S0P (Ajax)
文章代碼(AID): #1Agx_S0P (Ajax)