Search code examples
google-mapsionic-frameworkgeolocationdirection

Geo Intent, how to auto launch directions


Currently developing Ionic mobile app and have a get directions button on one of the pages.

Currently setting my intent like this

if(address.length !== 0){
    address = "(" + address + ")";
}
var location = getDrivingLocation();
var url = encodeURI(location.latitude + "," + location.longitude + "?q=" + location.latitude + "," + location.longitude + address);
window.location = "geo:" + url + "&z=18";

It launches the map and current spot, but I still need to press the get directions button manually on google maps to start directions. Is there anything in the URL that I can change to make it auto start?


Solution

  • You can try to use a URL scheme, URL scheme allows you to launch an IOS application from another IOS app. These are the supported URL schemes:

    • comgooglemaps:// and comgooglemaps-x-callback:// - These schemes allow you to launch the Google Maps app for iOS and perform one of several actions:

      • Display a map at a specified location and zoom level.

      • Search for locations or places, and display them on a map.

      • Request directions from one location to another. Directions can be returned for four modes of transportation: driving, walking, bicycling and public transit.

      • Add navigation to your app.

    • comgooglemapsurl:// - This scheme allows you to launch the Google Maps app for iOS using a URL derived from the desktop Google Maps website. This means that you can give your users a native mobile experience rather than simply loading the Google Maps website.

    For more information you can check this page.

    I don't know if this is what you want, but you can check this example. I think it will give you some idea.