Support

Account

Home Forums Front-end Issues Google Map not centering on bounds

Solving

Google Map not centering on bounds

  • In case anyone else has the same problem as me, with the Google Map in front-end appearing with the center on the equator or somewhere else, where your markers aren’t 😀

    Not sure why, but apparently this function:

    // fit to bounds
    map.fitBounds( bounds );

    does not seem to work sometimes.
    Instead use this function to center the map on the location of the bounds:
    map.panToBounds(bounds);

    I believe the Google Maps API has some kind of hiccup on this, because it’s not clear, why fitBounds wouldn’t work.

  • This is close to what Im looking for for my issue. fitBounds centers my map with multiple markers in a weird way. It should center the map over the Atlantic but for some reason it sets it over the Pacific ocean. I guess it tries to find the best way to set the map based on the marker locations.

    panToBounds seems to at least center the map in a better way. Thank you!

  • Do you also use Spiderfier and Clusterer?

    The fitBounds function still doesn’t seem to work and centers my map somewhere along the equator, so I believe it’s the same in your case?

    I will probably find a way with a different map script, like Leaflet or Open Street Map, because Google Maps doesn’t seem to recognize this issue and cannot recreate it (I asked for support there too).

    Let me know, if you find a different solution 😉

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.