Javascript Google地图未显示在V3中

Javascript Google地图未显示在V3中,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我已经编写了在我的位置上显示标记的代码,但是当我添加了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/javas

我已经编写了在我的位置上显示标记的代码,但是当我添加了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>

$(文档).ready(函数(){
$(“.contact_map.load”).append(“加载映射…”)
});
函数初始化(){
$(“.contact_map.load”).empty();
变量映射选项={
中心:新google.maps.LatLng(22.722337,75.881732),
缩放:8,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
标题:“你好,世界!”
});
}
google.maps.event.addDomListener(窗口“加载”,初始化)
marker.setMap(map);


变量标记仅存在于初始化函数内部,不能在外部使用。为此,请在函数外部定义此变量。此外,我没有看到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);

myLatlng似乎没有在代码中的任何地方定义,您似乎将侦听器设置为远离标记的创建?这在代码:center:new google.maps.LatLng(22.722337,75.881732)中定义。谢谢,我忘了初始化变量myLatlng