apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Extend Bounds with Markers on IE8 #456

Open GolfyMcG opened 9 years ago

GolfyMcG commented 9 years ago

Not sure if anyone has come across this but unfortunately a large percentage of our user base is on IE8 (Healthcare IT ><). We were able to easily get a map built and extend the bounds to fit the markers on all modern browsers and mobile, but for whatever reason extendBounds didn't work for us on IE8.

Our solution was as follows:

var markerData = $("#markers").data('markers');
var centerData = $("#markers").data('center');

var handler = Gmaps.build('Google');
function buildMap(){
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
        if(isNotIE) {
          markers = handler.addMarkers(markerData.concat(centerData));
          handler.bounds.extendWith(markers);
          handler.fitMapToBounds();
        } else {
          centerMarker = handler.addMarker(centerData[0]);
          handler.map.centerOn(centerMarker);
          handler.getMap().setZoom(12);
          handler.addMarkers(markerData);
        }
    });
};
buildMap();

I'm submitting this as an issue because I'm wondering whether there might be a method being used in the extendBounds or fitMapToBounds method that does not work in IE8. I might be wrong, but that was my guess. If you don't care about IE8 at all, feel free to ignore this, though! I wish I could!

apneadiving commented 9 years ago

nothing fancy in the code... Do you have a stacktrace please?

GolfyMcG commented 9 years ago

The best I can get is Object doesn't support this property or method for markers = handler.addMarkers(markerData.concat(centerData)); though this doesn't appear to break, to me. IE8 loads all the markers onto the map, but then fails to adjust the bounds. The above solution worked just fine with adding the markers after centering it on a single point.

If you're more familiar with the IE8 developer tools, I can dig in more but that's the extent of debugging I was capable of when trying to fix it before.