X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosSiteMapCache.java;h=03dc3cf5d67ebc8a3170d863d8557c75258452c1;hp=40c8ff6bf0dc078beff6f8b5016f8910ffe2f4c4;hb=9c4674d90f9b111e1b47abb7aee714ed12fa3aa5;hpb=ff332e640b27c6be37dabef58ebac350ac2347b2 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; }