gpt4 book ai didi

jQuery SlideToggle Google map 问题

转载 作者:行者123 更新时间:2023-12-01 03:45:42 25 4
gpt4 key购买 nike

我读过其他类似的线程,但没有任何问题/响应,这有助于使其足够简单以了解我需要做什么。我使用的是 jQuery 版本 1.7,这可能解释了为什么其他问题中发布的一些代码不相似。

Google map 加载到 SlideToggle 的 div 中,其中心点偏移到西北,并且相对于该 div 切换打开时显示的 map 部分不可见。我正在尝试显示一个非常简单的 map ,没什么花哨的。

jQuery(".toggle").click(function () {
// check the visibility of the next element in the DOM
jQuery(this).next().slideToggle(); // slide it down
});

我的 jQuery 知识有限,但我知道我需要在切换 div 后强制加载 iframe。我只是不知道如何实现这一目标! HTML/PHP 代码如下。

<span class="toggle">
View Map // with some CSS
</span>

<div id="maps" class="ui-helper-hidden">
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $latitude;?>,<?php echo $longitude;?>&amp;aq=&amp;t=m&amp;z=13&amp;output=embed&key=123456789"></iframe>
</div>

最佳答案

您可能需要考虑使用 JavaScript 和 Maps API 动态加载 map 。在此过程中,您将创建一个中心点对象,然后可以在切换回调函数中重用该对象来重置 map 的中心。像这样的东西应该有效。

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">

$(function () {

// create a center
var c = new google.maps.LatLng(-33.8790, 151.2064);

//create map options object
var mapOptions = {
zoom: 14,
center: c,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById('maps'), mapOptions);

$(".toggle").click(function () {
// check the visibility of the next element in the DOM
$(this).next().slideToggle(300, function(){
google.maps.event.trigger(map, "resize"); // resize map
map.setCenter(c); // set the center
}); // slide it down

});

});

</script>

关于jQuery SlideToggle Google map 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13733482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com