简体   繁体   English

如何在Google Maps v3中使用Twitter Bootstrap?

[英]How do I use Twitter Bootstrap with Google Maps v3?

I want to include Twitter Bootstrap's Tabbed Menus within a Google Maps project that is currently coded completely in javascript. 我想在目前完全用javascript编码的Google Maps项目中包括Twitter Bootstrap的选项卡式菜单。 Because Twitter relies on jQuery, I'm not sure how to use both of them together. 因为Twitter依赖jQuery,所以我不确定如何将两者一起使用。

When I try to import jQuery using this <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> none of my page will render anymore. 当我尝试使用此<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>导入jQuery时,无页面的内容将再次呈现。

I think I might have to use a plugin like jQuery-ui-map , but it would take too long to manually recode the whole site into jQuery (if that's what I have to do). 我认为我可能必须使用类似jQuery-ui-map的插件,但是将整个站点手动重新编码为jQuery会花费太长时间(如果这是我要做的)。 Is there a way to import bootstrap and jquery just for the purposes of the tabbed menu, but leave the rest of the site in javascript? 有没有一种方法可以仅出于选项卡式菜单的方式导入引导程序和jquery,而将其余网站保留在javascript中?

When you added the jQuery <script> tag in your test page, you removed the <script> tag that loads your own script. 在测试页中添加jQuery <script>标记时,您删除了加载自己的脚本的<script>标记。 That's why your load() function is undefined. 这就是为什么您的load()函数未定义的原因。

Your current code is: 您当前的代码是:

<script type="text/javascript"
   src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>

//<![CDATA[

var gmarkers = [];
var infoWindow = new google.maps.InfoWindow;
...

See how there's no <script> tag beginning your own script? 看看在您自己的脚本之前没有<script>标签吗?

With regard to your question about needing a jQuery plugin to use the Maps API with jQuery, no, you definitely don't need one. 关于您需要一个jQuery插件才能将Maps API与jQuery结合使用的问题,不,您绝对不需要。 I use jQuery and the Maps API together all the time. 我一直都在使用jQuery和Maps API。 Consider this: What is a jQuery plugin? 考虑一下:什么是jQuery插件? JavaScript code! JavaScript代码! Nothing else. 没有其他的。 Anything a jQuery plugin does, you can do in your own code. jQuery插件可以做的任何事情,您都可以用自己的代码完成。

(I suppose one could imagine that there may be some special bookkeeping that is needed to make jQuery and the Maps API work together, but that just isn't the case. jQuery doesn't care what's inside your map container.) (我想人们可以想象,要使jQuery和Maps API协同工作可能需要一些特殊的簿记,但事实并非如此。jQuery不在乎地图容器中的内容。)

As @geocodezip mentioned, if you find the map working but odd things happening with the formatting of elements inside the map (eg the pan/zoom control gets clipped), check for CSS selectors that affect too many elements, such as: 正如@geocodezip所提到的,如果您发现地图正常工作,但是地图内部元素的格式发生了奇怪的事情(例如,平移/缩放控件被裁剪),请检查影响太多元素的CSS选择器,例如:

img {
    /* anything here is dangerous! */
}

A selector like that will affect images inside the map, which should be left alone by your CSS. 像那样的选择会影响地图,这应该由单独的CSS留的图像。 It doesn't look like you have this problem in your current working test page, just something to be aware of if it happens. 看起来您当前的工作测试页中没有这个问题,只是需要注意的事情。

Also, just an unrelated tip, you don't need type="text/javascript" on your <script> tags, nor type="text/css" on your <style> tags. 同样,只是一个不相关的技巧,您不需要在<script>标记上type="text/javascript" ,也不需要在<style>标记上type="text/css"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM