[問題] google map多筆資料利用setTimeout做延遲顯示????
底下的問題不曉得有人知道嗎? 因為自己try很多次也都一直錯誤!
Q1.
目前想做延遲show資料在地圖上的功能,但將setTimeout放在showAddress函式裡好像不對
再者,要顯示資料我在<body>裡面呼叫寫好的js的showAddress為什麼沒動作呢?
只能放在<head></head>嗎?
網頁範例: http://edu2u.why3s.tw/ttt.html
Q2.地圖上Info的視窗寬度要怎樣限制呢? 是要加什麼在marker.openInfoWindowHtml中嗎?
<html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAV9gNhag3wL11lX
type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
var marker;
function initialize()
{
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
//加入地圖縮放工具
geocoder = new GClientGeocoder();
}
}
function createMarker(point,title,html)
{
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function()
{
marker.openInfoWindowHtml( //這邊限制Info視窗的寬度怎樣寫??
html,
{
maxContent: html,
maxTitle: title});
});
return marker;
}
function showAddress(address,dec)
{
if (geocoder)
{
geocoder.getLatLng(
address,
function(point)
{
if (!point)
{
alert(address + " 在google map上找不到");
}
else
{
if(marker) //移除上一個點
{
map.closeInfoWindow();
map.removeOverlay(marker);
}
map.setCenter(point, 16);
window.setTimeout(function(){ map.panTo(point,16);},3000);
//只要呼叫showAddress,就延遲3秒鐘,是這樣用的嗎?
var title = "地址";
marker = createMarker(point,title,dec);
map.addOverlay(marker);
marker.openInfoWindowHtml(
dec,
{
maxContent: dec,
maxTitle: title}
);
}
}
);
}
}
</script>
</head>
<div id="map" style="width: 400px; height: 300px">
</div>
<script type="text/javascript">
showAddress("台北市內湖區瑞光路441號","科技大樓");
//這邊呼叫那顯示的函式好像沒作用呢??
showAddress("台北市內湖區瑞光路430號","花市");
</script>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.193.176.104