地图作为div背景 - Google Maps API

时间:2014-08-07 22:04:57

标签: javascript api google-maps

我使用javascript代码一段时间后将谷歌地图加载为DIV背景。

// When the window has finished loading create our google map below
            google.maps.event.addDomListener(window, 'load', init);

            function init() {
                // Basic options for a simple Google Map
                // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
                var mapOptions = {
                    // How zoomed in you want the map to start at (always required)
                    zoom: 15,

                    // The latitude and longitude to center the map (always required)
                    center: new google.maps.LatLng(54.549047, 18.443433), // New York

                    // How you would like to style the map. 
                    // This is where you would paste any style found on Snazzy Maps.
                    styles: [   {       featureType:"all",      elementType:"all",      stylers:[       {           invert_lightness:true       },      {           saturation:10       },      {           lightness:30        },      {           gamma:0.5       },      {           hue:"#1C705B"       }       ]   }   ]
                };


                // Get the HTML DOM element that will contain your map 
                // We are using a div with id="map" seen below in the <body>
                var mapElement = document.getElementById('map');

                // Create the Google Map using out element and options defined above
                var map = new google.maps.Map(mapElement, mapOptions);
            }

完美无缺。但是,当我试图在那里加载一个指向我所在位置的标记时,它会崩溃。任何想法将适当放置这样的?我认为这是正确的代码(它不起作用..):

var myLatlng = new google.maps.LatLng(54.549047, 18.443433);
var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Hello World!'
  });

感谢您的帮助!

0 个答案:

没有答案