作者jami520 (我的生命因你而发光)
看板Google
标题[问题] google map多笔资料利用setTimeout做延迟显示????
时间Fri Aug 29 07:48:09 2008
底下的问题不晓得有人知道吗? 因为自己try很多次也都一直错误!
Q1.
目前想做延迟show资料在地图上的功能,但将setTimeout放在showAddress函式里好像不对
再者,要显示资料我在<body>里面呼叫写好的js的showAddress为什麽没动作呢?
只能放在<head></head>吗?
网页范例: http://edu2u.why3s.tw/ttt.html
Q2.地图上Info的视窗宽度要怎样限制呢? 是要加什麽在marker.openInfoWindowHtml中吗?
<html xmlns="
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