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 3f17188e0444b94ec58a86be4739eac98ea07464..43a0787eead32ac47b2ae51866bdb3deed0937a9 100644 (file)
                  
         <service android:name=".TelemetryService" />
 
                  
         <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>
         <meta-data android:name="com.google.android.gms.version"
                    android:value="@integer/google_play_services_version" />
     </application>
index 453e898ecf1af37b7cacf17961e9b3873872a044..1bcb67ef72e849c56f682a803bc815e1d26dcf90 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 +
                // 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 + ")");
 
                                 " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz +
                                 " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");
 
index b1cfcbd79c7460badbd1ab33c89c24818ac9b0b3..abd8c2407284f6adc70c949a4564e3d58e6074a9 100644 (file)
@@ -48,9 +48,21 @@ public class AltosMapStore {
                                              chlat, lat, chlon, lon, maptype_string, zoom, scale == 1 ? "" : String.format("-%d", scale), format_string));
        }
 
                                              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;
        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";
 
                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)
                        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
                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() {
        }
 
        public synchronized int status() {
@@ -209,24 +221,8 @@ public class AltosMapStore {
 
                                int new_status;
 
 
                                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();
                                notify_listeners(new_status);
                        } finally {
                                finish_fetcher();
index fd9256aa06fecf7bf4781ba3fa1905714b476153..6b660bb5494613ec442371cbb63ecf69808b5e2d 100644 (file)
@@ -20,10 +20,4 @@ package org.altusmetrum.altoslib_13;
 
 public class AltosVersion {
        public final static String version = "@VERSION@";
 
 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 e466f8b2c9f8c1433261ec98a0dd4c96eafe164d..e61b5d5205d96d15dc5816c0c6663188fa437d35 100644 (file)
@@ -270,9 +270,8 @@ public class AltosUIConfigure
                         constraints(0, 3));
                row++;
 
                         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++;
 
                         constraints(0, 3));
                row++;
 
index 1705745d794c01f7192ab42625a68736cc09e1b8..741fa013d854a8394fa068668849091687cd724e 100644 (file)
@@ -172,26 +172,12 @@ AM_CONDITIONAL(FATINSTALL, [test "x$FATDIR" != "xnone"])
 
 AC_SUBST(FATDIR)
 
 
 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_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
 AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_LN_S