Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle maps v3 - Error when zooming to markers
    text
    copied!<p>I am trying to load a google maps v3 element into my website, where a user can dynamically select some filters to show certain markers. The result is then serialized into a JSON file for the maps object to use to set the specified markers.</p> <p>I've tried to make a test page as follows:</p> <pre><code>@section headerScripts { &lt;script src="~/Scripts/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var map; var latlng = new google.maps.LatLng(56.29216, 10.34912); var markerList = []; function initialize() { var mapOptions = { zoom: 7, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); } function addMarkers(stores) { for (var i = 0; i &lt; stores.length; i++) { var marker = new google.maps.Marker({ position: new google.maps.LatLng(stores[i].Latitude, stores[i].Longitude), map: map, title: stores[i].Name }); markerList.push(marker); } zoomToMarkers(); } function zoomToMarkers() { var latlngbounds = new google.maps.LatLngBounds(); markerList.forEach(function (n) { latlngbounds.extend(n); }); map.setCenter(latlngbounds.getCenter()); map.fitBounds(latlngbounds); } $(document).ready(function () { initialize(); $.getJSON("/Product/GetStore/", addMarkers); }); &lt;/script&gt; } &lt;div id="map-canvas" style="width: 500px; height: 500px;"&gt;&lt;/div&gt; </code></pre> <p>It sets the markers alright, and that works, but I'd like a function to zoom, so that only the markers on the maps is shown in the "zoom". But when I call the zoomToMarkers (based on a function I found online) - I get an error from the google maps js file: </p> <p><strong>Unhandled exception at line 16, column 353 in <a href="https://maps.gstatic.com/intl/da_dk/mapfiles/api-3/12/9/main.js" rel="nofollow">https://maps.gstatic.com/intl/da_dk/mapfiles/api-3/12/9/main.js</a> 0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'lat'</strong></p> <p>I have no idea why this is happening, as it seems that alot of other people have gotten it to work. Can you guys help?</p>
 

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