Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps JavaScript API - Automate Zoom Level?
    text
    copied!<p>I'm working with multiple map markers. Currently I use <code>map.fitBounds(bounds);</code> in my JavaScript to resize the map. bounds contains multiple <code>LatLng</code> objects.</p> <p>What am i doing wrong? Because it zooms out too far :-(</p> <p><a href="https://i.stack.imgur.com/oT4hz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oT4hz.png" alt="enter image description here"></a></p> <p>JavaScript source</p> <pre><code>var geocoder, map; $(document).ready(function(){ var coll_gmap = $(".gmap"); if ( coll_gmap.length != 0 ) { //initiate map geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 13, center: latlng, mapTypeControl: true, navigationControl: true, scaleControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN}, mapTypeId: google.maps.MapTypeId.ROADMAP } var bounds = new google.maps.LatLngBounds(); //loop all addressen + insert into map map = new google.maps.Map(coll_gmap[0], myOptions); coll_gmap.each(function(index) { if (geocoder) { geocoder.geocode( { 'address': $(this).attr("address")}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); bounds.extend(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { console.log("Geocode was not successful for the following reason: " + status); }//end if status }); //end if geocoder.geocode } //end if geocoder }) //end coll_gmap each map.fitBounds(bounds); }//end if coll_gmap length /* console.log("Script created by NicoJuicy");*/ }); //end onload </code></pre> <p>HTML source</p> <pre><code>&lt;div class="gmap" address="SomeAddress1" style="width:700px;height:350px"&gt;&lt;/div&gt; &lt;div class="gmap" address="someAddress2"&gt;&lt;/div&gt; </code></pre>
 

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