需要帮助谷歌地图方向面板在FancyBox中显示
Need help getting Google maps directionsPanel to display in a FancyBox
我目前正在为一个网站开发一小部分功能。基本上,我想在页面上显示一个端口的地图,并允许用户在下面输入他们的地址,以便找到方向。一旦他们点击了"获取方向"链接,就会打开一个奇特的框,其中的内容是包含谷歌方向面板的div。
以下是我遇到的问题。-calcRoute()函数调用链接的onClick。因此,div以前没有填充过。结果如何?第一次单击时,fancybox会生成空的。第二,它按照预期生成。我想出的一个解决方案是手动设置div的大小。然而,这会产生滚动和样式问题,我宁愿避免。
这是我的代码(注意,这是我创建的一个小页面,用于在移植到我们的实际网站之前测试我的代码):
<script type="text/javascript">
var map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var manhattanPort = new google.maps.LatLng(40.767899, -73.995825);
var myHouse = new google.maps.LatLng(40.419866, -74.152263);
var geoCoder;
function initialize() {
geoCoder = new google.maps.Geocoder();
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
center: manhattanPort,
zoom:14,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}
function calcRoute(){
var address = document.getElementById("address").value;
var end = manhattanPort;
var request = {
origin: address,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
geoCoder.geocode( {'address':address}, function(results,status){
if(status == google.maps.GeocoderStatus.OK){
map.setCenter(results[0].geometry.location);
} else{
alert("Geocode was not succesful for the following reason: " + status);
}
});
directionsService.route(request, function(result, status){
if( status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(result);
}
});
}
function doClear(theText){
if (theText.value == theText.defaultValue){
theText.value = ""
}
}
</script>
</head>
<body onload="initialize()">
<table align="right">
<tr>
<td align="right" width="330" height="380">
<div id="map_canvas" style="width:100%; height:100%"></div>
</td>
</t
</table>
<table align="center">
<tr>
<td align="center">
<div>
<input name="start_address" id="address" type="text" value="Enter An Address To Get Directions" onFocus="doClear(this)" size="100"/>
<!-- <input type="button" value="Get Directions" onClick="calcRoute();"/> -->
<a class="fancybox" href="#directionsPanel" onClick="calcRoute();">Get Directions</a>
</div>
</td>
</tr>
<tr>
<td align="center">
<div id="directionsPanel"></div>
</td>
</tr>
</table>
</body>
</html>
现在很明显,我错过了粉丝盒本身的脚本。让我知道提供这些是否会有所帮助。
谢谢你的帮助!
在directionsService.route()
的回调中调用$.fancybox.update()
相关文章:
- 需要帮助谷歌地图方向面板在FancyBox中显示
- 如何在用户按下F5键或单击浏览器时显示自定义的fancybox's后退/关闭按钮
- 类似facebook的按钮没有显示在fancybox标题中
- 可以't让fancybox完全显示退出按钮或在初次点击时淡出
- 使用load()加载外部文件,然后使用fancybox插件进行修改并显示
- FancyBox将DIV的内容显示为iFrame类型
- 阻止Fancybox显示图像
- 如何在谷歌地图标记上显示FancyBox视频
- 在fancybox中显示动态图像
- PDF 未显示在 IE9、10 和 11 的 fancybox 2 iframe 中
- 在jquery fancybox中,ie 7没有显示ajax模式弹出窗口
- 通过嵌入客户端网站的Javascript显示JQuery和Fancybox的弹出窗口
- 在关闭浏览器窗口之前显示fancybox弹出窗口
- fancybox iframe内容未通过jquery函数显示
- 图片在fancybox Edit上显示了3次
- Fancybox链接显示另一个Fancybox
- Fancybox显示白色而不是图像
- Jquery Fancybox显示图像失败
- 如何在按下提交按钮后激活Fancybox或如何让用户在提交后使用Fancybox显示注册屏幕
- 如何让fancybox显示一个“是/否确认框”?通过href onclick