I am trying to display a map on my web page to get the coordinates from it. It works fine, I can drag the marker and get the coordinates in the input field.
But my problem arises when I load a webpage. Everything is well displayed, but the map, here you can see how the map is displayed:

But if at this moment I change the size of the web page, I mean, if it were a full screen, set it to half. Or make it a little bigger or smaller if it were just part of the screen. Then you will see the correct map: 
(This is not the place I know. I took an image from 2 reboots)
I am creating a webpage in HTML, but I call it as if they are different webpages. When you load the index, you get a button with this
href:<a href="#openMap">
And, the part shown will be:
<div data-role="page" id="openMap" data-theme="e"> <div data-role="header" data-id="fixedNav" data-position="fixed"> blablabla <div data-role="content"> <form action=""> <div id="map_canvas" style="width:500px; height:300px"></div> blablabla
And all divs, forms ... are properly closed. I have many input fields and fields that I have not added here.
Then on my google map script I have the following:
var map; function initializeNewMap() { var myLatlng = new google.maps.LatLng(43.462119485,-3.809954692009); var myOptions = { zoom: 14, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var marker = new google.maps.Marker({ draggable: true, position: myLatlng, map: map, title: "Your location" }); }
But I have no idea why I need to resize. Is this a way to solve this problem?
EDIT: I am adding additional information:
I call the part of the web page that has this map:
$(document).on("pageinit", '#openMap', function() {
I tried to put
google.maps.event.trigger(map, 'resize');
right after him, but nothing happens.
DECISION:
I found a solution in another question ( Downloading Google Maps v3 partially in the upper left corner, the resize event does not work , message by Jan Devlin):
As one user said, I need to resize the map. But this line does not work. I added this code at the end of the initialization function:
google.maps.event.addListenerOnce(map, 'idle', function() { google.maps.event.trigger(map, 'resize'); });
Thus, it is called only after the map is displayed.