0

I am working on a somewhat complex google map and have run into an issue with fitbounds. It works perfectly... most of the time, but occasionally ignores my bounds and loads the map in the middle of the ocean.

My markers still appear and had loaded correctly if i zoom out and search for them.

Any thoughts?

Markers from json string

Code (stripped out 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);**

Please also note: I don't get any js errors on the page.

  • Do all your markers have valid latitudes and longitudes? Where is the closing bracket for your .getJSON call (before or after the map.fitBounds)? Can you provide a jsfiddle or a link to a live map that exhibits the problem? – geocodezip Sep 25 '13 at 19:25
  • Middle of the ocean usually means invalid lat,lng pairs (or strings instead of numbers) – Chad Killingsworth Sep 26 '13 at 20:38

0 Answers0