basicallydan
basicallydan

Reputation: 2152

Using Google Maps Directions in Android App

I'm trying to develop an Android App to go with my web app www.scroutenise.com, so I made a backend API to mimic the behaviour of the Javascript app which returns

  1. A Google Maps DirectionsResult
  2. A bunch of Google Maps Places

Both are in the same format provided by the Google Maps API. Great - with JS I can easily render this on a Google Map.

So far in my App I'm successfully communicating with the API and getting the full results - keep in mind the API is a WebSockets API so there's no URL - and I've got a Google Map showing.

The only thing I can't find documentation or tutorials for is how to display directions on the map. I'm sure I could figure out how to place Markers, but the directions aspect is a pretty important aspect of my app. Is it even possible? Are there some Ts&Cs that Google has to stop people from making a directions-related app?

Thanks for reading, I hope somebody can help :)

Upvotes: 0

Views: 4264

Answers (3)

NickUnuchek
NickUnuchek

Reputation: 12897

String uri= "https://www.google.com/maps/dir/" + 
    fromLat + "," + fromLng + "/" + toLat + "," + toLng;

Intent mapCall = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

OR only location of "to" and user must turn on GPS:

String uri= "https://www.google.com/maps/dir//" + toLat + "," + toLng;

Intent mapCall = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

Upvotes: 0

javram
javram

Reputation: 2645

In Android, you can specify driving directions through the use of an Intent:

String geoUriString = "http://maps.google.com/maps?" + 
   "saddr=" + srcLat + "," + srcLng + "&daddr=" + dstLat + "," + dstLng;

Intent mapCall = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUriString));

Then based on the apps installed on your device (navigation, maps, etc) the user will be able to receive directions from one of those apps.

Upvotes: 4

andunslg
andunslg

Reputation: 791

I don't get what you means by directions here, But you can draw path using the way described in this post.

http://csie-tw.blogspot.com/2009/06/android-driving-direction-route-path.html

Upvotes: 1

Related Questions