简体   繁体   English

Javascript和Google Maps API

[英]Javascript and the Google Maps API

I'm in a spot of bother and my hairline is on the chopping block. 我在一个麻烦的地方,我的发际线在砧板上。 When I integrated the maps API on this site, ritaknoetze.com , everything worked perfectly. 当我在这个站点ritaknoetze.com上集成maps API时,一切都很完美。

However, copying that exact code for a different demo website, scarabpaper , the map doesn't show up at all? 但是,为不同的演示网站, 圣甲虫复制那些确切的代码,地图根本不显示? Could someone show me the ropes on what I'm doing wrong? 有人能告诉我我做错了什么吗?

Here's the code I got from Google itself that I modified for my WordPress theme/installation: 这是我从谷歌本身获得的代码,我修改了我的WordPress主题/安装:

JavaScript: JavaScript的:

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

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

<script type="text/javascript">
          function initialize() {
            var myLatlng = new google.maps.LatLng(-34.009839, 22.78101);
            var myOptions = {
              zoom: 9,
              center: myLatlng,
              navigationControl: true,
              mapTypeControl: false,
              scaleControl: false,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

            var image = '<?php bloginfo('template_url')?>/assets/googlemaps_marker.png';
            var myLatLng = new google.maps.LatLng(-34.009839, 22.78101);
            var beachMarker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                icon: image
            });
          }
        </script>

My HTML where the javascript goes: 我的JavaScript所在的HTML:

<div class="contact_container">
    <div id="map_canvas"></div>
    <div class="clearfloat"></div>
</div>

My CSS for the affected divs 我的受影响的div的CSS

#map_canvas {
    width: 880px;
    height: 300px;
    margin-left: 10px;
    margin-bottom: 30px;
    margin-top: 10px;
    float: left;
    border: 1px solid #dedcdc;}

.contact_container {    /*container for ALL the contact info*/
    background-color: #fff;
    border: 1px solid #dedcdc;
    width: 900px;
    margin-top: 30px;
    padding: 20px;
    padding-bottom: 0;}

Any Help would be greatly appreciated... 任何帮助,将不胜感激...

You're never calling the initialize() method. 你永远不会调用initialize()方法。 It works if you call that method, even using a console. 如果您调用该方法,即使使用控制台也可以使用。

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

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