Open google maps app from url android

Looking for information about ProntoForms features and functionality? Visit our Product Documentation Portal.

  • About
  • Google/Apple Maps URLs
    • Location Search
    • Get Directions Using an Address
    • Using Coordinates
  • Bing Maps URLs
    • Location Search
    • Get Directions Using an Address
    • Using Coordinates
  • Dispatch a Map Link with Coordinates Collected in a Form

 

About

Using the Data Type Launcher functionality, it is possible for a mobile user to launch a map in their web browser (or in a map app) using a correctly formatted map URL. This feature allows administrators to dispatch an address (such as a mobile user's next site visit) and accompany it with a map to aid their users in navigating to the address. Alternatively, users can manually enter their own URL into the form, and launch the map in their web browser or an app.

Using a Map App

The first time a user launches a map URL from ProntoForms, they may be asked if they would like to open it in a web browser or in the corresponding app, if there is one (i.e. A http://maps.google.com URL will prompt the user to open it with the Google Maps app).  If this app is not installed, the user will be prompted to install it or open the URL in a web browser.  Some apps can open URLs intended for other mapping services (Google Maps can open an Apple Maps URL). 

Configuring the Form

The availability of this feature to users is controlled on a per-question basis the Form Builder.  The default options are configured to allow the launcher functionality. Please note that a URL (including a map URL) only be launched from a question with a URL data type -- a URL entered in a simple text textbox, for example, will be read as a string of text rather than a URL, and therefore cannot be launched.

To turn on the URL launcher, mouse over a question with a URL data type and select Edit Properties.  Enter the URL Properties tab and check off both "Allow the user to click the address to open the link" and "Open the link in the user's external browser."

If the same URL should be provided to users every time they use the form, add the URL as a default value for the question.  This is also found under Edit Properties, in the Text Properties tab.

[ top ]

 

Google Maps or Apple Maps URLs

While the examples below show a Google Maps URL, Apple Maps URLs are formatted the same way.  Simply replace maps.google.com with maps.apple.com. Note that if the Google Maps app is on the device and has been previously used to open map URLs from ProntoForms, Apple Maps URLs may still open in Google Maps by default.

Formatting Tips:

  • Be sure to use a ? before the first parameter in all cases. Additional parameters do not require this.
  • Characters must be URL encoded.  Replaces spaces with a +.
  • Separate parameters (such as a start and end point) with a &.
  • This resource provides information on additional parameters such as "near", traffic overlays, etc.  It is also possible to select a terrain type, zoom level, etc.
  • Format: http://maps.google.com/?q=your+query
  • q= indicates a query.  Anything entered after this will behave as if entered into the Google Maps query box.
  • Example: http://maps.google.com/?q=100+Main+Street+Buffalo+NY

Get Directions Using an Address

  • Format: http://maps.google.com/?&daddr=End+Point+Address
  • daddr= indicates a destination (end) address.
  • Only an end point is required, provided the user selects the "Allow Google Maps to Use My Current Location" option when prompted.
  • Example: https://maps.google.com/?daddr=Parliament+Hill+Ottawa
  • Optionally use saddr= to indicate a start point.
  • Example: https://maps.google.com/?saddr=45.424807,-75.699234&daddr=%a[GPS  Label 2][coordinates.latitude],%a[GPS Label 2][coordinates.longitude]

    Although the current answers are great, none of them did quite what I was looking for, I wanted to open the maps app only, add a name for each of the source location and destination, using the geo URI scheme wouldn't work for me at all and the maps web link didn't have labels so I came up with this solution, which is essentially an amalgamation of the other solutions and comments made here, hopefully it's helpful to others viewing this question.

    String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f(%s)&daddr=%f,%f (%s)", sourceLatitude, sourceLongitude, "Home Sweet Home", destinationLatitude, destinationLongitude, "Where the party is at");
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    intent.setPackage("com.google.android.apps.maps");
    startActivity(intent);
    

    To use your current location as the starting point (unfortunately I haven't found a way to label the current location) then use the following

    String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", destinationLatitude, destinationLongitude, "Where the party is at");
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    intent.setPackage("com.google.android.apps.maps");
    startActivity(intent);
    

    For completeness, if the user doesn't have the maps app installed then it's going to be a good idea to catch the ActivityNotFoundException, then we can start the activity again without the maps app restriction, we can be pretty sure that we will never get to the Toast at the end since an internet browser is a valid application to launch this url scheme too.

            String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", 12f, 2f, "Where the party is at");
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setPackage("com.google.android.apps.maps");
            try
            {
                startActivity(intent);
            }
            catch(ActivityNotFoundException ex)
            {
                try
                {
                    Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                    startActivity(unrestrictedIntent);
                }
                catch(ActivityNotFoundException innerEx)
                {
                    Toast.makeText(this, "Please install a maps application", Toast.LENGTH_LONG).show();
                }
            }
    

    P.S. Any latitudes or longitudes used in my example are not representative of my location, any likeness to a true location is pure coincidence, aka I'm not from Africa :P

    Share a map or location.
    On your computer, open Google Maps..
    Go to the directions, map, or Street View image you want to share..
    On the top left, click Menu ..
    Select Share or embed map. If you don't see this option, click Link to this map. ... .
    Copy and paste the link wherever you want to share the map..

    How do I integrate Google Maps into an app?

    On this page..
    Set up the development environment..
    Set up an Android device..
    Create a Google Maps project in Android Studio..
    Set up in Cloud Console..
    Add the API key to your app..
    Look at the code. Maps activity file. Module Gradle file. XML layout file..
    Deploy and run the app..
    Get the embed code:.
    Go to Google maps. In the Search Google Maps text box, type in the address of the location you want to display on your web page..
    When the map appears, click on the Share icon..
    Select the Embed tab on the Share window..
    Click on Copy HTML..