Android Navigation Using Google Maps
March 30th, 2011My app links to Google Maps navigation by sending the start and end points to Google Maps using ther following code.
String directions="http://maps.google.com/maps?saddr="+startlatitude+","+startlongitude+
"&daddr="+endLatitude+","+endLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse(directions));
This works fine and launches Google Maps. However I had another intent that was launching without knowing the current location. I wanted Google Maps to get the location for me but couldn’t work out how to force Maps to use my location as the start point.
As it turns out the solution was obvious, if you dont send the start address parameter Maps assumes you mean from the current location so the code becomes this.
String directions="http://maps.google.com/maps?daddr="+endLatitude+","+endLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse(directions));
This opens Google Maps with ‘My location’ listed as the start point so you have to then press the ‘Go’ button but saves me the effort of getting the location first.
