How to cache Google Maps? - google-maps

Im trying to cache Google Maps Api, to reduce requests.
In their optimize recommendations they write about web-server proxying.
I made it with nginx. Cached everything in the world, but not these requests to Google Maps Api!
I saved locally script of Google Maps, it cached, but it sends requests from its inside.
I see in development console, for example, tiles of map loaded from "memory cache", but requests still counting in google dashboard.
I heard, its not possible, but they wrote about caching in their official docs.
Where I can read about this? What I can do?

You can't.
The only part of the Google Maps API you can cache is certain geocoding results (and even then, only certain results, and only for a limited time). There is no way to cache the interactive maps on your server.
Do not attempt to cache any Javascript or other content used to display Google Maps in the browser. The contents of those scripts may change without notice, and many of your visitors will have those scripts in their browser cache already (e.g, from visiting other web sites which use Google Maps).

Related

Google Map offline in web application

How to download all the images in google map to avail the offline access forever in the web application?
I can able to perform the online operations using
src="//maps.googleapis.com/maps/api/js?sensor=false&language=en"
but I need Offline access forever by downloading everything once in online.
I am afraid the solution that you try to implement is against of the terms of service. Please refer to paragraphs 10.1 (a):
No access to APIs or Content except through the Service. You will not access the Maps API(s) or the Content except through the Service. For example, you must not access map tiles or imagery through interfaces or channels (including undocumented Google interfaces) other than the Maps API(s).
and 10.5 (d) of ToS:
No caching or storage. You will not pre-fetch, cache, index, or store any Content to be used outside the Service, except that you may store limited amounts of Content solely for the purpose of improving the performance of your Maps API Implementation due to network latency (and not for the purpose of preventing Google from accurately tracking usage), and only if such storage:
is temporary (and in no event more than 30 calendar days);
is secure;
does not manipulate or aggregate any part of the Content or Service; and
does not modify attribution in any way.
https://developers.google.com/maps/terms#10-license-restrictions
The offline access via Maps JavaScript API is not available at the moment. There is a feature request in the public issue tracker:
https://issuetracker.google.com/issues/35827808
Please star this feature request to express your interest and receive further updates from Google.

How does Google keep track of map loads without API key?

I am implementing Google Maps in my web application. Since Version 3 I don't need an API key for accessing their servers.
Google is limiting the requests, though.
How are they doing that? If external users are accessing my website, one map load is generated.
Do I have now about 25,000 map loads per IP address or how to they
recognize my application?
They probably use the location/domain of the current document(this detail will be sended to the Authentication-service).
But as long as it's not documented this may only be an assumption, you'll have to ask google how they do it.

How can I run a google maps request offline?

I'm making a visualization using google maps. However, I have to make many direction requests to google maps.
Is there a way to "download" a section of a map, along with all its bus/car/bike routing information, so the direction requests can be done locally?
If it's possible, can you give a rough example to get me in the right direction?
Thanks :)
No there's no offline access to the Maps API, for either viewing tiles for associated services like routing/directions.
Additionally, you must always ensure the results of these types of requests are displayed on a Google map (which must be publicly available for free, according to the terms of service).
If you are looking for the ability to do offline routing with your own dataset, there are a number of open source routing engines available.

Do Google API keys work with Google Maps web services, e.g. geocoding?

I'm using Google Maps web services to perform server-side (reverse) geocoding.
I've got a browser-side and server-side Google API key from the Google APIs Console, which permits the Google Maps JS API to use higher request quotas, and enables pay-per-use for overages (successfully tested in-browser via JS). But the server-side key doesn't seem to work on web services requests.
For example, this URL works fine:
http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlng=43.477329,-80.548601
But if you add a "key=..." parameter, as in the other APIs, I get a REQUEST_DENIED status.
Am I doing something wrong, or is this just not supported on the web services APIs (yet)? Will it be supported in the future?
See also
request_denied when i include key=my_api_key
Nope, you're not doing anything wrong.
Unfortunately, enforcing tight limits on the Google Geocoding API, also called "Server-Side Geocoding", is Google's design. If your app needs more than 2,500 Server-Side Geocodes per day, then you'll need to upgrade to their Google Maps API for Business product.
Hold on, it gets worse.
If your app's server IP address is shared with other apps, that 2,500 request daily limit applies to ALL of them. This includes apps that share the same server IP address as you, but don't belong to you! This can be a common situation with any PaaS, like Google App Engine or Heroku. So, even if your app works flawlessly today, there is no guarantee that it's still going to work tomorrow.
In the article, "Geocoding Strategies", Google indicates the solution is to "almost always" use "Client-Side Geocoding" via the Geocoding Service, part of the Google Maps JavaScript API V3. The primary reason is that limits are enforced per user, per session. Requests like this shouldn't run up against quota limits unless you're executing geocode batches on the client (not a typical use case).
One golden nugget from the "Geocoding Strategies" article: Design a page that takes user input, calls the client-side Geocode service method, then passes that information to your server app where it can be processed, and hopefully cached. This is FAR from ideal, but if upgrading to Google Maps API for Business isn't an option, it might be the only way to go.
Good luck!
According to this post, your API key should work as one of the three option for requests over 25,000 loads per day.
https://developers.google.com/maps/faq#usagelimits

Using Google Maps V3 offline, e.g. with cache-manifest?

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&region=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&region=GB, or would that be a bad move?
(Sorry for this rather beginner question, let me know if I can explain better!)
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.
Required Readings
First take a look at the Google Code blogpost here: http://googlecode.blogspot.com/2010/04/google-apis-html5-new-era-of-mobile.html
Then have a read at Missouri State's own post: http://blogs.missouristate.edu/web/2010/05/12/google-maps-api-v3-developing-for-mobile-devices/
The Technique
You must cache every URL used by Google Maps
Employ methods to battle Chrome's and Firefox's stubborn caching methods by removing it from "offline websites"
All customizations must be client-side in javascript
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/
Caveats
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.
I have http://maps.google.com/maps/api/js?sensor=false in the CACHE section of cache.manifest, together with my application files and there isn't any problem.
Although, I believe you also have to cache other files that the Google Maps API requests. You can take a look at the files downloaded by your app and include them.
Not possible!
Google map CDN URLs have dynamic nature,
https://mts0.googleapis.com/vt?pb=!1m4!1m3!1i8!2i234!3i15...
https://mts1.googleapis.com/vt?pb=!1m4!1m3!1i8!2i233!3i155!!...
No wildcard characters are allowed in CACHE section of the HTML5 cache manifest files
We can not have some thing like,
CACHE MANIFEST
/css/style.css
/js/libs/modernizr-2.0.6.min.js
/js/libs/jquery-2.1.4.js
http://mts0.googleapis.com/*
http://mts1.googleapis.com/*
http://fonts.googleapis.com/*
NETWORK:
*
I had a google map project that I needed offline. I found Bing Maps (https://www.bingmapsportal.com/ISDK/AjaxV7) is much better offline and switched my project over to that and I'm happy. I ran the google and bing version side-by-side in offline mode and Bing was great. Whereas google would immediatey fail on tile loads, Bing maps cached more tiles and appeared to even resize zoomed tiles to at least give you something in offline mode.
I know the question here is about Google maps; but if you don't care about bing vs. google and really just need offline support, I'd highly recommend trying Bing maps. It solved it for me.