title: Android Phonegap - How to Open Native Google Maps Application
body: <p>I'm working on an Android application using Phonegap and am having trouble figuring out how to open the native Google Maps application to display directions. I don't have any issue opening a map by inserting a URL but opening the application has me stumped. So far I have only been able to find Phonegap related suggestions for development on the iOS platform.</p>
  
  <p>I have added Google Maps to the whitelist permissions, am including the correct Cordova.js file and google maps link in my script tag, have the correct permissions in my AndroidManifest.xml file, included Cordova.jar and Google Map API in my build path, have the Phonegap xml folder in the res directory, js file in my assets/www directory, jar file in the libs directory.</p>
  
  <p>What I am trying to accomplish: <br /></p>
  
  <ol>
  1. When a link is clicked, open the native Google Maps application. If the application is not installed on the device, notify the user that Google Maps is not installed and must be installed. <br />
  <ul>a. I am already checking for network connectivity and handling that as it should be done.
  </ul>
  2. Google Maps opens displaying directions from the user's current location to the location of the link clicked.
  </ol>
  
  <p>The example below works on my Android device exactly the same as it does on iOS but obviously does not open the actions Google Maps application. </p>
  
  <pre><code>&lt;a&gt; href="http://maps.google.com/maps?q=TD Washington DC"&gt;&lt;img src="img/ico_pin.png" /&gt;White House&lt;/a&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The second example adds on to the first by including the end location although I wasn't able to figure out how to insert the current location. Most importantly though, it still doesn't open the Google Maps application.</p>
  
  <pre><code>&lt;a href="javascript:openMaps('daddr=1600+Pennsylvania+Ave+NW+Washington+DC+20500+USA');"&gt;&lt;img src="img/ico_pin.png" /&gt;White House&lt;/a&gt;
  
  function openMaps(querystring) {
      var maproot = '';
      maproot = 'http://maps.google.com/maps?saddr=Current+Location&amp;';
      window.location = maproot + querystring;
  }
  </code></pre>
  
  <p>In the third example below, I'm able to display a map within my application. It does show the correct route (from an overhead view from point A to point B) but again doesn't open the actual Google Maps application.</p>
  
  <pre><code>&lt;a id="whDirections" href="#mm_directions" onclick="getDirections()"&gt;
                      &lt;img src="img/ico_pin.png" /&gt;White House&lt;/a&gt;
  
  &lt;div data-role="content"&gt;
      &lt;div class="ui-bar-c ui-corner-all ui-shadow" style="padding: 1em;"&gt;
          &lt;div id="mapdirections_canvas" style="height: 300px;"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  function getDirections() {
      var directionsService = new google.maps.DirectionsService();
      var map;
      var directionsDisplay = new google.maps.DirectionsRenderer();
      var mapOptions = {
          zoom: 9,
          zoomControl: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("mapdirections_canvas"), mapOptions);
      directionsDisplay.setMap(map);
  
      var myLatLng = new google.maps.LatLng(gmmLat, gmmLong);
      if (document.getElementById("whDirections")) {
          var request = {
              origin: myLatLng,
          destination: new google.maps.LatLng(38.897096, -77.036545), 
              travelMode: google.maps.TravelMode.DRIVING
      };
      directionsService.route(request, function(result, status) {
          if (status == google.maps.DirectionsStatus.OK) {
              directionsDisplay.setDirections(result); 
          }
      });
  }
  </code></pre>
  
  <p>If anyone has a link or any idea on this, I would really appreciate the help. Other than a 'Hello World' app, this is my first mobile application. Please let me know if I have missed anything or if I am just doing this completely wrong. If any additional information is needed, please let me know.</p>
  
  <p>Thanks in advance for the help.</p>