Google Maps V3 API - fitBounds randomly works, but sometimes ignores mid-ocean boundaries and loads

I am working on a somewhat complicated google map and ran into a problem with fitbounds. It works great ... most of the time, but sometimes ignores my borders and loads a map in the middle of the ocean.

My markers are still displayed and loading correctly if I zoom out and looked for them.

Any thoughts?

Json string markers

Code (deleted for simplicity):

**var mybounds = new google.maps.LatLngBounds();** $.getJSON(callRoot + JSON.stringify(mapSearchParams), function(data) { $.each(data.markers, function (i, marker) { **var position = new google.maps.LatLng(marker.latitude, marker.longitude);** addMarker(position, findIcon(marker.category, "marker"), marker.category, marker.title, marker.subtitle, marker.destNodeGUID, marker.documentURL, marker.primaryImageURL, marker.isFeatured); **mybounds.extend(position);** }); // end .each **map.fitBounds(mybounds);** 

Also note: I am not getting any js errors on the page.

0
source share

Source: https://habr.com/ru/post/1205034/


All Articles