{"id":7062,"date":"2014-05-19T04:11:13","date_gmt":"2014-05-19T04:11:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/19\/how-do-i-load-google-maps-js-api-in-phonegap-to-use-it-multiple-times-collection-of-common-programming-errors\/"},"modified":"2014-05-19T04:11:13","modified_gmt":"2014-05-19T04:11:13","slug":"how-do-i-load-google-maps-js-api-in-phonegap-to-use-it-multiple-times-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/19\/how-do-i-load-google-maps-js-api-in-phonegap-to-use-it-multiple-times-collection-of-common-programming-errors\/","title":{"rendered":"How do I load Google Maps JS API in PhoneGap to use it multiple times?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m developing a PhoneGap application with multiple pages and some of them show a map.<\/p>\n<p>Now what I&#8217;m trying to do is to load the Google Maps API when the page loads so I can access it whenever I need it. Now there are several options:<\/p>\n<ol>\n<li>\n<p>Load the script <em>without<\/em> a callback parameter in the URL <code>...(url)&amp;callback=functionName<\/code> when the page loads<br \/>\n<strong>Result:<\/strong> the google.maps object is created but it&#8217;s almost empty. The functions are all missing.<\/p>\n<\/li>\n<li>\n<p>Load the script <em>with<\/em> a callback parameter in the URL when the page loads<br \/>\n<strong>Result:<\/strong> the functions in google.maps are all available, but when I create a Map, I only get an empty inside the container element. So it seems it starts to create the map, but the rest is missing.<br \/>\nThe funny thing here is: it works perfectly in desktop browsers, but it does not in a phonegap application &#8211; doesn&#8217;t matter if Android or iOS.<\/p>\n<\/li>\n<li>\n<p>Load the script <em>with<\/em> a callback, but every time a map should be displayed<br \/>\n<strong>Result:<\/strong> it seems to work, but an error\/a warning in the console shows up, telling me there may occur unexpected problems if I load the Maps API more than once. Plus it creates unnecessary server requests which slow down the application.<\/p>\n<\/li>\n<\/ol>\n<p>Running option 2 in Ripple Emulator tells me that the application tries to open a <code>InAppBrowser<\/code> when I open a page that should display a map. I don&#8217;t have much experience with <code>InAppBrowser<\/code>, so I don&#8217;t know what this is trying to tell me or if it even is related to the problem&#8230;<\/p>\n<p>Currently I&#8217;m including the script via a simple<\/p>\n<pre><code>var script = document.createElement('script');\nscript.type ...\nscript.src = 'http:\/\/maps.googleapis.com\/.....';\ndocument.body.appendChild(script);\n<\/code><\/pre>\n<p>Does anyone know how to include and use the API in a case like this? Also the parameters I want to pass to the <code>new google.maps.Map()<\/code> constructor differ. So I need a flexible way to do this.<\/p>\n<p>Thanks for any help<br \/>\nAndreas<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m developing a PhoneGap application with multiple pages and some of them show a map. Now what I&#8217;m trying to do is to load the Google Maps API when the page loads so I can access it whenever I need it. Now there are several options: Load the script without a callback parameter in the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7062","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7062"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7062\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}