繁体   English   中英

Google地图未在V3中显示

[英]Google Map is not displaying with V3

我编写了在我的位置显示标记的代码,但是当我添加了marker.setmap方法时,在错误的地方未加载地图

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=ABBByyyeessssf77Z6S8c-M-T3Ea2j-uFczWXFxKh0&sensor=true">
</script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".contact_map .load").append("Loading Map...")
    });

function initialize() {
            $(".contact_map .load").empty();
    var mapOptions = {
      center: new google.maps.LatLng(22.722337, 75.881732),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
    var marker = new google.maps.Marker({
            position: myLatlng,
            title:"Hello World!"
            });
  }

  google.maps.event.addDomListener(window, 'load', initialize)
     marker.setMap(map);
</script>
<div class="contact_container">
<div class="contact_image">
</div>
    <div class="contact_map">
        <p class="load"></p>
    <div id="map_canvas"></div>
    </div>

</div>

变量标记仅存在于initialize函数内部,不能在外部使用。 为此,请在函数外部定义此var。 另外,我在任何地方都看不到var myLatLng

var marker;

function initialize() {
//your other code code
marker = new google.maps.Marker({ //don't use the word 'var' in this line
        position: myLatlng,
        title:"Hello World!"
        });
}

  google.maps.event.addDomListener(window, 'load', initialize)
  marker.setMap(map);

暂无
暂无

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

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