I'm writing an HTML5 mobile application that uses Google Maps V3 with a custom layer of OpenStreetMap tiles.
The OSM tiles (from tile.openstreetmap.org
) are set to cache for just over 24 hours, and I'm using a cache-manifest for all my HTML/JS/CSS.
So the application could in theory be used offline, except the Google Maps interface isn't happy when offline.
It always wants to call to the Google Maps server at http://maps.google.com/maps/api/js?sensor=false®ion=GB
- when this fails, Google Maps fails to load.
Is there any way to use Google Maps V3 API offline?
Could I cache-manifest http://maps.google.com/maps/api/js?sensor=false®ion=GB
, or would that be a bad move?
(Sorry for this rather beginner question, let me know if I can explain better!)
Once you have the area you'd like to cache in view, type “okay maps” into the search box. Google will take a moment to “pre-load” the area and then save the copy to your device's offline cache. Once it's cached you can use the map at any time, even in Airplane mode.
IMHO you can't cache it. The API script calls objects on the Google server. At most, you can capture the results and cache them as images (but then you lose interactivity).
You won't be charged until your usage exceeds $200 in a month. Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).
Google coders themselves have tackled this problem and unfortunately the information isn't well disseminated. But yes you can use cache-manifest to do exactly what you've described.
Your cache file will look like (as per Missouri State):
CACHE MANIFEST
/map/mobile/examples/template.aspx
/map/mobile/examples/template.css
/map/mobile/examples/template.js
NETWORK:
http://maps.gstatic.com/
http://maps.google.com/
http://maps.googleapis.com/
http://mt0.googleapis.com/
http://mt1.googleapis.com/
http://mt2.googleapis.com/
http://mt3.googleapis.com/
http://khm0.googleapis.com/
http://khm1.googleapis.com/
http://cbk0.googleapis.com/
http://cbk1.googleapis.com/
http://www.google-analytics.com/
http://gg.google.com/
You will need to be entirely HTML5-based and recognize the impacts this will have on your users. This situation is handy where either your users are up-to-date on browser standards/devices or you have control over user choices.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With