Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a first step to get what you want to do:</p> <pre><code>var map; //&lt;-- This is now available to both event listeners and the initialize() function var mapCenter; // Declare a variable to store the center of the map var centerMarker; // declare your marker function initialize() { var mapOptions = { center: new google.maps.LatLng(LAT,LNG), zoom: 10, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, scrollwheel: false, keyboardShortcuts: false, }; map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); // Create a new marker and add it to the map centerMarker = new google.maps.Marker({ position: new google.maps.LatLng(LAT,LNG), map: map, title: 'Title', animation: google.maps.Animation.DROP }); mapCenter = map.getCenter(); // Assign the center of the loaded map to the valiable } google.maps.event.addDomListener(window, 'load', initialize); google.maps.event.addDomListener(window, "resize", function() { // Here you set the center of the map based on your "mapCenter" variable map.setCenter(mapCenter); }); </code></pre> <p><strong>Edit:</strong> Based on @Chad Killingsworth comment: You may want to add an 'idle' event handler to the map to set the <code>mapCenter</code> variable. You can achieve this like this:</p> <pre><code>google.maps.event.addListener(map,'idle',function(event) { mapCenter = map.getCenter(); }); </code></pre> <p>Description of the 'idle' event from the doc: </p> <blockquote> <p>This event is fired when the map becomes idle after panning or zooming. </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload