Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only issue I had with your script was the following line in the <code>initialize()</code> function:</p> <pre><code>var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); </code></pre> <p>By declaring <code>var map</code>, your script is just declaring a local variable named <code>map</code>, as opposed to using the global <code>map</code> variable declared at the top of your script.</p> <p>By removing <code>var</code>, the script uses the global variable and runs fine:</p> <pre><code>map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); </code></pre> <p>Finally, to get the geocoded map to load on the link click, change <code>onclick</code> for your geocoded address to <code>onclick="initialize();codeAddress();"</code>.</p> <p><strong>Added:</strong></p> <p>Try combining your <code>initialize()</code> and <code>codeAddress()</code> methods into the following:</p> <pre><code>function initialize() { geocoder = new google.maps.Geocoder(); var address = document.getElementById('address').value; geocoder.geocode({ 'address': address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { var myOptions = { zoom: 18, center: results[0].geometry.location, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } else { alert('Geocode was not successful for the following reason: ' + status); } }); } </code></pre> <p>And then just call <code>initialize()</code> from your link.</p> <p>Basically, what we're doing is taking the call to <code>geocoder.geocode()</code> that <code>codeAddress()</code> was performing and inside the resulting delegate, we're using <code>results[0].geometry.location</code> to initialize the map. This way, the temporary latlong doesn't need to be displayed.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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