作者kk08744 (sexyboy)
看板Ajax
标题[问题] google map 与路径规划相关问题
时间Sat Sep 12 23:35:55 2009
各位前辈好,小弟最近在写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
1F:推 guancheng:GDirections.load()的第二个参数好像是要用json来传送吧 09/14 03:55
2F:→ guancheng:{ "locale": "zh_TW" } 试看看这样吧~~ 09/14 03:58
3F:→ guancheng:ps. 其实我也没用过~只是看了一好文件好像是这样@@a 09/14 04:02
4F:→ kk08744:楼上大大~我改成 09/14 10:18
5F:→ kk08744:directions.load("from: 銝緍憭批飞 to: 衔貗怨뮊 09/14 10:18
6F:→ kk08744:directions.load("from: 世新大学 to: 台北火车站", 09/14 10:20
7F:→ kk08744:{ "locale": "zh_TW" }); 09/14 10:20
8F:→ kk08744:依然不行... 09/14 10:20
9F:推 guancheng:刚刚去申请了key来试了一下~程式没有问题,是地址的问题 09/14 20:53
10F:→ guancheng:我用"from: 世新大学 to: 台北火车站"也是不行的 09/14 20:54
11F:→ guancheng:但是用完整地址却可以,忽然想到加了个Taiwan给他吧 09/14 20:55
13F:→ guancheng:我直接把Taiwan加在送出的程式里了 09/14 20:58
14F:→ guancheng:这样直接输入"世新大学"跟"台北火车站"也找的到 09/14 20:59
15F:→ kk08744:感谢大大^^~ 09/15 07:51
16F:推 nick9063937:请guancheng大大 放上你测试的完整code 11/27 10:28
17F:→ nick9063937:因为我也遇到一样的问题 11/27 10:28