Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图初始化可以';添加标记时看不到映射变量_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图初始化可以';添加标记时看不到映射变量

Javascript 谷歌地图初始化可以';添加标记时看不到映射变量,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我对谷歌地图进行了以下初始化: function initialize() { var mapOptions = { zoom: 15, center: myLatLng, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DRO

我对谷歌地图进行了以下初始化:

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);
    };
尝试添加标记时,我得到错误:

未捕获引用错误:未定义映射


如何查看此地图或将标记正确添加到地图中?

似乎您没有适合标记的myLatLng位置,请尝试添加一个,例如:myLatLng=new google.maps.LatLng(45.00,10.00)


它消除了错误,但没有显示标记。该标记是initialize()函数中的标记?如果这是OP存在的问题,我将看不到映射。我得到的错误是
未捕获引用错误:未定义myLatLng
。将标记的定义移动到
initialize
函数中(当前
map
变量是函数的本地变量)。()
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);
    };