summaryrefslogtreecommitdiff
path: root/altosui/AltosSiteMapCache.java
diff options
context:
space:
mode:
authorBdale Garbee <bdale@gag.com>2014-01-22 20:55:41 -0700
committerBdale Garbee <bdale@gag.com>2014-01-22 20:55:41 -0700
commit9884ca1449167a06bd2cebc7d28353eeac592493 (patch)
tree9fde328b3a5971c67954e669c1ba27042821fd8c /altosui/AltosSiteMapCache.java
parent8e669694a60d34e2ea0f8f6b189e0bc3605d94d7 (diff)
parent0ef0c50536e5eb6ad3455b5828983307edbab828 (diff)
Merge branch 'branch-1.3' into debian
Diffstat (limited to 'altosui/AltosSiteMapCache.java')
-rw-r--r--altosui/AltosSiteMapCache.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/altosui/AltosSiteMapCache.java b/altosui/AltosSiteMapCache.java
index 40c8ff6b..03dc3cf5 100644
--- a/altosui/AltosSiteMapCache.java
+++ b/altosui/AltosSiteMapCache.java
@@ -25,8 +25,13 @@ import java.net.URL;
import java.net.URLConnection;
public class AltosSiteMapCache extends JLabel {
+ static final long google_maps_ratelimit_ms = 1200;
+ // Google limits static map queries to 50 per minute per IP, so
+ // each query should take at least 1.2 seconds.
+
public static boolean fetchMap(File file, String url) {
URL u;
+ long startTime = System.nanoTime();
try {
u = new URL(url);
@@ -70,6 +75,16 @@ public class AltosSiteMapCache extends JLabel {
}
return false;
}
+
+ long duration_ms = (System.nanoTime() - startTime) / 1000000;
+ if (duration_ms < google_maps_ratelimit_ms) {
+ try {
+ Thread.sleep(google_maps_ratelimit_ms - duration_ms);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
return true;
}