Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Window only showing part of the map

Tags:

google-maps

I have used Google Maps on many websites in the past, but I have been posed with an issue I haven't experienced before. The maps window is showing, but it's only showing maps segments from the top left, and anything after that (even when i'm navigating around), nothing loads to the right. Its as if the window that is navigated around has an internal offset that is pushing it off the side of the viewport. Does anyone know what could be causing it?

EDIT

I have just discovered that when the window is resized, the map refreshes, and the layout is fixed.

The map is contained within a tab that is shown via javascript (and hidden via display:none). The tab container is loaded via ajax, and when it loads, the loadMap function is called. I tried postponing the loadMap function by enclosing it within a setTimeout function that delays the creation of the map by 1 second, but it still does the same (requiring the window to be resized to fix it)

like image 523
topherg Avatar asked Mar 28 '13 18:03

topherg


People also ask

Why is my Google Maps not showing the way?

Google Maps won't work if the location service is disabled on your smartphone. In order for Google Maps to work optimally, location service needs to be enabled. Enabling location is easy for Android users. Simply, swipe down the Android Quick Settings Panel and tap on the Location/GPS option to enable location.

Why won't My Maps show the map?

Update Google Maps Many app glitches on Android and iOS can quickly be fixed by updating your apps to the latest version. The same is valid for Google Maps. Launch the Play Store or App Store app, enter Google Maps in the search bar and check if there's an Update button next to the app.


1 Answers

This is a typical problem you'll run into when the map container is hidden or has zero dimensions at the time you create the map.

The usual solution is to do one of these:

  • Defer creating the map until the container element is visible and sized properly, or

  • Call google.maps.event.trigger( map, 'resize' ) after the map becomes visible or is resized. This event tells the Maps API to readjust its calculations of what's visible in the map.

It sounds like you've already solved it by using the first option, which is definitely the better choice of the two. Your page will load faster because you aren't spending the time to create an invisible map. If you do have a situation where the map size may change (e.g. a resizable window) then you can trigger the resize event when that happens.

like image 89
Michael Geary Avatar answered Oct 21 '22 16:10

Michael Geary