1

I've got home page in jquery mobile that has link to another page where map is all over the screen with header on top. When I go to that link with the map, the map loads just partly (as you can see on screenshot) and when I try to move it, it jumps back.

Map screenshot

As you can see the canvas is properly loaded, because down there is google map logo and Terms of use. What is wrong with that?

One fact: When I refresh the map page (not starting on home page) or when I resize the browser window when I'm on map page, it shows up perfectly fine.

10
  • show us your page markup. It could be a div problem in data-role=content. Commented Mar 13, 2013 at 16:57
  • try this $(document).bind('pageinit', '[data-role='page']#map', function() instead of $(document).bind('pageinit', function() Commented Mar 13, 2013 at 17:07
  • Nope, still the same issue, but that's great piece of code, it won't load the map every time I change the page :) Commented Mar 13, 2013 at 17:11
  • Maybe I'm looking for an event that fires after the DOM is loaded, not before, which as far as I'm concerned, 'pageinit' does. But I can't find that event anywhere on google. Commented Mar 13, 2013 at 17:12
  • sorry, my bad, that's because it's initiated and loaded inside the DOM. Commented Mar 13, 2013 at 17:16

4 Answers 4

3

Trigger a refresh on the map. This can happen when the map container changes size, or is hidden initially and then shown. Same thing happens, for instance, when using jQuery UI tabs and the map is initialized on on a hidden tab.

google.maps.event.trigger(map, 'resize') 
Sign up to request clarification or add additional context in comments.

1 Comment

That's a great stuff, too. Thanks, I was looking for this in connection with something else.
2

The map is loaded into DOM on pageinit, therefore it doesn't now obtain the right screen/window measures. Thus, you have to bind initializing the map to pagebeforeshow as it allow the map to get the screen size.

Here's how it works.

$(document).on('pagebeforeshow', '[data-role="page"]#map' , function() 

instead of

$(document).bind('pageinit', function() 

4 Comments

Hi Omar, my function is called initializeMap(). Where should I place the document call you suggested above? thanks
@Malloc hi, which JQM version are you using? Can you post a separate question with all details? :)
Hi. I am using jquery 1.11.0 and jquery mobile 1.4.2. Ok I am posting a separate question
0

I had the same problem, and finally solved it by triggering the 'resize' twice. Like this:

$("#mapelement").height(10); $("#mapelement").width(10); google.maps.event.trigger(googlemap, 'resize'); setTimeout(function() { adjustMapSize(); // set the correct size of #mapelement google.maps.event.trigger(googlemap, 'resize'); updateMap(); // center the map and display markers }, 500); 

Comments

0
$(document).on('pageshow', "#name-page", function() { initialize(); }); 

Try this,

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.