title: Get Search Location from Index Page & Zoom to Location on Map Page
body: <p>I'm trying to setup a redirect from the index page to the map page, so if a user searches for an address using the Places Autocomplete library, they get redirected to the map page with the location that they searched for. The index page does not include a map, but just the search bar with Places Autocomplete library.</p>
  
  <p>The function I've setup on the index page is as follows:</p>
  
  <pre><code>var place;
  function indexSearch() {
      // Get Address Field and Attach Places Autocomplete
      var input = document.getElementById('autocomplete');
      var autocomplete = new google.maps.places.Autocomplete(input);
  
      // Get Place When Place_Changed Event if Fired
      google.maps.event.addListener(autocomplete, 'place_changed', function () {
          place = autocomplete.getPlace();
          if (typeof place !== 'undefined') {
              window.location.href = 'map';
              // Don't know what to do here
              // as I can't use map.panTo(place.geometry.location) because
              // map does not exist on index page.
          }
      });
  
      // Erase Previous Address if Search Bar is Clicked
      inputIndex.onclick = function () {
          inputIndex.value = '';
      } 
  }
  </code></pre>
  
  <p>Do I need to include something in the <code>initialize()</code> function which is responsible for setting up the map?</p>
  
  <pre><code>function initialize() {
      var mapOptions = {
          zoom: 17,
          center: {
              lat: -33.8666,
              lng: 151.1958
          },
          disableDefaultUI: true
      };
      var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
      // Catch place and pan map to its location
  }
  </code></pre>
  
  <p><strong>Edit</strong>: At least provide a reason for downvote.</p>
  
  <p>I'm looking into using <code>localStorage</code> or <code>sessionStorage</code>. Pass the lat and lng to either of those, and retrieve the location when the map page is loading. Is this an optimal solution? Will update with answer once I have the solution.</p>