Skip to content

Instantly share code, notes, and snippets.

@msomu
Created October 6, 2015 18:43
Show Gist options
  • Select an option

  • Save msomu/28cc8068a027cbccdfd6 to your computer and use it in GitHub Desktop.

Select an option

Save msomu/28cc8068a027cbccdfd6 to your computer and use it in GitHub Desktop.
this is how url should be appended
// Will contain the raw JSON response as a string.
String forecastJsonStr = null;
String format = "json";
String units = "metric";
int numDays = 7;
// Construct the URL for the OpenWeatherMap query
// Possible parameters are avaiable at OWM's forecast API page, at
// http://openweathermap.org/API#forecast
//URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7");
final String FORECAST_BASE_URL =
"http://api.openweathermap.org/data/2.5/forecast/daily?";
final String QUERY_PARAM = "q";
final String FORMAT_PARAM = "mode";
final String UNITS_PARAM = "units";
final String DAYS_PARAM = "cnt";
Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon()
.appendQueryParameter(QUERY_PARAM,params[0])
.appendQueryParameter(FORMAT_PARAM,format)
.appendQueryParameter(UNITS_PARAM,units)
.appendQueryParameter(DAYS_PARAM,Integer.toString(numDays))
.build();
URL url = new URL(builtUri.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment