PDA

View Full Version : Google API and CACHE MANIFEST



ecreatures
27 Nov 2010, 8:18 AM
I did an application that use some map features. The purpose of this web app (iPad and iPhone) is to be able to be used offline.
As we cannot cache the : http://maps.google.com/maps/api/js?sensor=true

how can we deal to have the app working offline without being blocked by Google API call?

I put the google api call in the NETWORK section of my manifest file but the webapp won't launch if offline

Is there a conditional expression I could use in my code to solve this.

VinylFox
27 Nov 2010, 9:48 AM
I had trouble with this same thing - have not found a solution, but I do have a work around.


if (navigator.onLine) {

ecreatures
27 Nov 2010, 9:55 AM
Thanks, are you using that in the header that call the <script>?

In fact do you load the script only if you're online?

VinylFox
27 Nov 2010, 11:30 AM
Inside the 'if' I create a script tag - so yes, It only loads the script if your online.

ecreatures
27 Nov 2010, 11:34 AM
OK I got it thanks, I'll ry this tomorrow

ecreatures
29 Nov 2010, 11:00 AM
Did not work for me. The app once offline keeps requesting connection in order to launch

here's what I used :

if (navigator.onLine){<?php print("<script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\"></script>"); ?> }

Noticed also a flash of code on the page before the app lauches when online.
I'll need to find something else.

VinylFox
29 Nov 2010, 11:05 AM
I'm not sure how that code you wrote would ever work. You need to actually create and insert a script tag using JavaScript.


if (navigator.onLine) {
(function(){
var st = document.createElement('script');
st.type = 'text/javascript';
st.async = true;
st.src = 'http://www.blah.com/script.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(st, s);
})();
}

NOTE: even though the code block says PHP, the code is all JavaScript.

ecreatures
29 Nov 2010, 12:03 PM
I'll try your solution wich is more sealess than mine.
One question, have you ever done a Sencha app that uses a fallback URL in the manifest file? In those case we could use another index for offline mode.

VinylFox
29 Nov 2010, 12:11 PM
Not sure - I haven't played with the FALLBACK section yet.

jmoraltu
23 Jan 2011, 1:16 PM
Any solution for this problem so far? I am trying to do the same and I got an error and the application does not load the map even if I am offline

clabasky
4 Oct 2011, 2:35 PM
has anyone figured this out yet??!?~o)

digeridoopoo
6 Oct 2011, 6:28 AM
I am looking into this as well. Maybe ultimately we will have to use something like OpenStreetMap, which is completely offline? Some iPhone/iPad apps seem to use it. The only post I could find so far was this one which seems quite complicated:

http://www.sencha.com/forum/showthread.php?109367-get-xml-of-openstreetmap

digeridoopoo
7 Oct 2011, 12:06 AM
I found this in the Google maps terms:

No Pre-Fetching, Caching, or Storage of Content. You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation if you do so temporarily, securely, and in a manner that does not permit use of the Content outside of the Service; and (ii) any content identifier or key that the Maps APIs Documentation specifically permits you to store. For example, you must not use the Content to create an independent database of “places.”

Have a look at this example bottom of the screen:

http://openlayers.org/dev/examples/?q=mobile

Have to do some more reading, but I wonder if this example would be much easier to cache??

:-)

:-)

digeridoopoo
2 Dec 2011, 7:41 AM
I read on a forum that someone had managed to successfully cache Google Maps API 3 by doing the following:

'You need to add these files below in the NETWORK section of the cache manifest file:


http://mt0.google.com/
http://mt1.google.com/
http://mt2.google.com/
http://mt3.google.com/
http://maps.google.com/
http://maps.gstatic.com/
http://gg.google.com/

The site here has a different list:
http://blogs.missouristate.edu/web/2010/05/12/google-maps-api-v3-developing-for-mobile-devices/

Has anyone tried this or had any progress? I might give it a shot soon when I have time...


:-)