谷歌地图初始化在添加标记时看不到地图变量



我有以下初始化谷歌地图:

function initialize() 
    {
        var mapOptions = {
            zoom: 15,
            center: myLatLng,
            mapTypeControl: true, 
            mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
            },
            zoomControl: true,
            scaleControl: true,
            scrollwheel: true,
            disableDoubleClickZoom: true,
        };
        var map = new google.maps.Map(document.getElementById("googleMap"),
            mapOptions);
        }
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        title: 'Hello World!'
      });
    google.maps.event.addDomListener(window, "load", initialize);
    };

当尝试添加标记时,我得到错误:

Uncaught ReferenceError: map is not defined

我如何才能看到这个地图或添加一个标记正确的地图?

似乎你没有适当的myLatLng位置为您的标记尝试添加一个例子:myLatLng = new google.maps.LatLng(45.00, 10.00);

function initialize() 
    {
        var mapOptions = {
            zoom: 15,
            center: myLatLng,
            mapTypeControl: true, 
            mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
            },
            zoomControl: true,
            scaleControl: true,
            scrollwheel: true,
            disableDoubleClickZoom: true,
        };
        var map = new google.maps.Map(document.getElementById("googleMap"),
            mapOptions);
        }
    var myLatLng = new google.maps.LatLng(45.00, 10.00);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        title: 'Hello World!'
      });
    google.maps.event.addDomListener(window, "load", initialize);
    };

相关内容

  • 没有找到相关文章