From 3ac332535de814ba072c7a0a2ff606fc2c616e1a Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Thu, 17 Feb 2022 08:28:38 +0100 Subject: [PATCH] WIP adding google maps uri support --- .../nextcloudmaps/utils/GoogleMapsUri.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GoogleMapsUri.java diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GoogleMapsUri.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GoogleMapsUri.java new file mode 100644 index 0000000..444d26a --- /dev/null +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GoogleMapsUri.java @@ -0,0 +1,33 @@ +package it.danieleverducci.nextcloudmaps.utils; + +import android.content.Context; +import android.content.pm.PackageManager; +import android.net.Uri; + +/** + * Google maps doesn't honor geouri standard, instead implements its own uri. + * A geouri opens google maps, but the position is ignored, so it is needed to use gmaps own uri. + * Utility to check if gmaps is installed and generate a gmaps uri + */ +public class GoogleMapsUri { + + public static boolean isGoogleMapsInstalled(Context context) { + try { + context.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + public static Uri createGmapsUri(double lat, double lon) { + // Check coords validity + if (lon <= -180 || lon >= 180 ) + throw new IllegalArgumentException("Invalid longitude: " + lon); + if (lat <= -90 || lat >= 90) + throw new IllegalArgumentException("Invalid latitude: " + lat); + + String uriStr = "https://www.google.com/maps/search/?api=1&query=" + lat + "," + lon; + return Uri.parse(uriStr); + } +}