Skip to content

Instantly share code, notes, and snippets.

@codephillip
Last active October 17, 2017 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codephillip/2edbed76d625ee552db9f9fdf1c3f31b to your computer and use it in GitHub Desktop.
Save codephillip/2edbed76d625ee552db9f9fdf1c3f31b to your computer and use it in GitHub Desktop.
https://maps.googleapis.com/maps/api/directions/json?origin=0.3181614,32.5736069&destination=0.3184610990987622,32.55381792783737&sensor=false&mode=driving
// Method 1
String MAP_BASE_URL = "https://maps.googleapis.com/maps/api/directions/json?";
Uri.Builder builtUri = Uri.parse(MAP_BASE_URL)
.buildUpon()
.appendQueryParameter("origin", origin.latitude + "," + origin.longitude)
.appendQueryParameter("destination", dest.latitude + "," + dest.longitude)
.appendQueryParameter("sensor", "false")
.appendQueryParameter("mode", "driving");
String url = builtUri.build().toString();
// Method 2
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("maps.googleapis.com")
.appendPath("maps")
.appendPath("api")
.appendPath("directions")
.appendPath("json")
.appendQueryParameter("origin", origin.latitude + "," + origin.longitude)
.appendQueryParameter("destination", dest.latitude + "," + dest.longitude)
.appendQueryParameter("sensor", "false")
.appendQueryParameter("mode", "driving");
String url = builder.build().toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment