[ js ] google map 與路徑規劃相關問題
各位前輩好,小弟最近在寫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
09/14 03:55, 1F
→
09/14 03:58, , 2F
09/14 03:58, 2F
→
09/14 04:02, , 3F
09/14 04:02, 3F
→
09/14 10:18, , 4F
09/14 10:18, 4F
→
09/14 10:18, , 5F
09/14 10:18, 5F
→
09/14 10:20, , 6F
09/14 10:20, 6F
→
09/14 10:20, , 7F
09/14 10:20, 7F
→
09/14 10:20, , 8F
09/14 10:20, 8F
推
09/14 20:53, , 9F
09/14 20:53, 9F
→
09/14 20:54, , 10F
09/14 20:54, 10F
→
09/14 20:55, , 11F
09/14 20:55, 11F
→
09/14 20:57, , 12F
09/14 20:57, 12F
→
09/14 20:58, , 13F
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
11/27 10:28, 16F
→
11/27 10:28, , 17F
11/27 10:28, 17F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章