altoslib: Switch to maps.altusmetrum.org when no google map key is available
authorKeith Packard <keithp@keithp.com>
Sun, 7 Oct 2018 02:29:01 +0000 (19:29 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 7 Oct 2018 02:48:41 +0000 (19:48 -0700)
The map key is only usable from maps.altusmetrum.org at this point,
and that service will be proxying for everyone in the near future.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/AndroidManifest.xml.in
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altoslib/AltosMapStore.java
altoslib/AltosVersion.java.in
altosuilib/AltosUIConfigure.java
configure.ac

index 3f17188..43a0787 100644 (file)
                  
         <service android:name=".TelemetryService" />
 
-        <meta-data android:name="com.google.android.maps.v2.API_KEY"
-                   android:value="@GOOGLEKEY@"/>
         <meta-data android:name="com.google.android.gms.version"
                    android:value="@integer/google_play_services_version" />
     </application>
index 453e898..1bcb67e 100644 (file)
@@ -678,7 +678,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener,
                // Display the Version
                mVersion = (TextView) findViewById(R.id.version);
                mVersion.setText("Version: " + BuildInfo.version +
-                                (AltosVersion.has_google_maps_api_key() ? " maps" : "") +
                                 " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz +
                                 " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");
 
index b1cfcbd..abd8c24 100644 (file)
@@ -48,9 +48,21 @@ public class AltosMapStore {
                                              chlat, lat, chlon, lon, maptype_string, zoom, scale == 1 ? "" : String.format("-%d", scale), format_string));
        }
 
+       public static String google_maps_api_key = null;
+
+       private static String google_map_url(AltosLatLon center, int zoom, int maptype, int px_size, int scale, String format_string) {
+               return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&scale=%d&sensor=false&maptype=%s&format=%s&key=%s",
+                                    center.lat, center.lon, zoom, px_size, px_size, scale,
+                                    AltosMap.maptype_names[maptype], format_string, google_maps_api_key);
+       }
+
+       private static String altos_map_url(AltosLatLon center, int zoom, int maptype, int px_size, int scale, String format_string) {
+               return String.format("https://maps.altusmetrum.org/altos-map?center=%.6f,%.6f&zoom=%d",
+                                    center.lat, center.lon, zoom);
+       }
+
        private static String map_url(AltosLatLon center, int zoom, int maptype, int px_size, int scale) {
                String format_string;
-               int z = zoom;
 
                if (maptype == AltosMap.maptype_hybrid || maptype == AltosMap.maptype_satellite || maptype == AltosMap.maptype_terrain)
                        format_string = "jpg";
@@ -58,14 +70,14 @@ public class AltosMapStore {
                        format_string = "png32";
 
                for (int s = 1; s < scale; s <<= 1)
-                       z--;
+                       zoom--;
 
-               if (AltosVersion.has_google_maps_api_key())
-                       return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&scale=%d&sensor=false&maptype=%s&format=%s&key=%s",
-                                            center.lat, center.lon, z, px_size/scale, px_size/scale, scale, AltosMap.maptype_names[maptype], format_string, AltosVersion.google_maps_api_key);
+               px_size /= scale;
+
+               if (google_maps_api_key != null)
+                       return google_map_url(center, zoom, maptype, px_size, scale, format_string);
                else
-                       return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&scale=%d&sensor=false&maptype=%s&format=%s",
-                                            center.lat, center.lon, z, px_size/scale, px_size/scale, AltosMap.maptype_names[maptype], format_string);
+                       return altos_map_url(center, zoom, maptype, px_size, scale, format_string);
        }
 
        public synchronized int status() {
@@ -209,24 +221,8 @@ public class AltosMapStore {
 
                                int new_status;
 
-                               if (!AltosVersion.has_google_maps_api_key()) {
-                                       synchronized (fetch_lock) {
-                                               long startTime = System.nanoTime();
-                                               new_status = fetch_url();
-                                               if (new_status == AltosMapTile.fetched) {
-                                                       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();
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               } else {
-                                       new_status = fetch_url();
-                               }
+                               new_status = fetch_url();
+
                                notify_listeners(new_status);
                        } finally {
                                finish_fetcher();
index fd9256a..6b660bb 100644 (file)
@@ -20,10 +20,4 @@ package org.altusmetrum.altoslib_13;
 
 public class AltosVersion {
        public final static String version = "@VERSION@";
-
-       public final static String google_maps_api_key = "@GOOGLEKEY@";
-
-       public static boolean has_google_maps_api_key() {
-               return google_maps_api_key != null && google_maps_api_key.length() > 1;
-       }
 }
index e466f8b..e61b5d5 100644 (file)
@@ -270,9 +270,8 @@ public class AltosUIConfigure
                         constraints(0, 3));
                row++;
 
-               pane.add(new JLabel (String.format("AltOS version %s (%smaps key)",
-                                                  AltosVersion.version,
-                                                  AltosVersion.has_google_maps_api_key() ? "" : "no ")),
+               pane.add(new JLabel (String.format("AltOS version %s",
+                                                  AltosVersion.version)),
                         constraints(0, 3));
                row++;
 
index 1705745..741fa01 100644 (file)
@@ -172,26 +172,12 @@ AM_CONDITIONAL(FATINSTALL, [test "x$FATDIR" != "xnone"])
 
 AC_SUBST(FATDIR)
 
-AC_ARG_WITH(google-key, AS_HELP_STRING([--with-google-key=PATH],
-           [Set the file to read the google maps API key from (defaults to ~/altusmetrumllc/google-maps-api-key)]),
-           [GOOGLEKEYFILE=$withval], [GOOGLEKEYFILE=$HOME/altusmetrumllc/google-maps-api-key])
-
-if test -r "$GOOGLEKEYFILE" -a -s "$GOOGLEKEYFILE"; then
-       GOOGLEKEY=`cat "$GOOGLEKEYFILE"`
-       HAVE_GOOGLE_KEY="yes"
-else
-       GOOGLEKEY='null'
-       HAVE_GOOGLE_KEY="no"
-fi
-
 AC_ARG_ENABLE(faketime, AS_HELP_STRING([--enable-faketime],
               [Use faketime program to ensure pdf files are reproducible (default=no)]),
              [FAKETIME=$enableval], [FAKETIME=no])
 
 AM_CONDITIONAL(FAKETIME, [test x$FAKETIME = xyes])
 
-AC_SUBST(GOOGLEKEY)
-
 AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_LN_S