簡體   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