From aab5873c87d6ecfe0854751746f80d4bc7ebeffa Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Mon, 20 Jan 2014 04:52:43 +1000 Subject: AltosSiteMapPreload: only load 49 maps Google Static Maps API limits queries to 50 maps per IP per minute, so querying a 7x7 array instead of a 9x9 array seems more likely to work well. --- altosui/AltosSiteMapPreload.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'altosui/AltosSiteMapPreload.java') diff --git a/altosui/AltosSiteMapPreload.java b/altosui/AltosSiteMapPreload.java index fd648abc..7112fed6 100644 --- a/altosui/AltosSiteMapPreload.java +++ b/altosui/AltosSiteMapPreload.java @@ -213,7 +213,7 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener AltosMapPos lat; AltosMapPos lon; - final static int radius = 4; + final static int radius = 3; final static int width = (radius * 2 + 1); final static int height = (radius * 2 + 1); @@ -326,7 +326,7 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener pane.setLayout(new GridBagLayout()); - map = new AltosSiteMap(4); + map = new AltosSiteMap(radius); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; @@ -464,4 +464,4 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener setLocationRelativeTo(owner); setVisible(true); } -} \ No newline at end of file +} -- cgit v1.2.3 From 7a8551fe8e5f0a90cbc494842715a96f08c11900 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Mon, 20 Jan 2014 19:38:21 +1000 Subject: altosui: rate limit map downloads --- altosui/AltosSiteMapCache.java | 15 +++++++++++++++ altosui/AltosSiteMapPreload.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'altosui/AltosSiteMapPreload.java') 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; } diff --git a/altosui/AltosSiteMapPreload.java b/altosui/AltosSiteMapPreload.java index 7112fed6..66399557 100644 --- a/altosui/AltosSiteMapPreload.java +++ b/altosui/AltosSiteMapPreload.java @@ -213,7 +213,7 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener AltosMapPos lat; AltosMapPos lon; - final static int radius = 3; + final static int radius = 5; final static int width = (radius * 2 + 1); final static int height = (radius * 2 + 1); -- cgit v1.2.3