Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public static void downloadOpeningHours()
  2. {
  3. String apiKey = "AIzaSyAyEB14KWKzlAngKDJcbcIF6vs5R-s8sqk";
  4. for (Results place : Database.results) {
  5. String query = "https://maps.googleapis.com/maps/api/place/details/json?placeid=" + place.getReference() + "&fields=name,opening_hours,photo,place_id&key=" + apiKey;
  6. OkHttpClient httpClient = new OkHttpClient();
  7. final String[] jsonResponse = new String[1];
  8. Request request = new Request.Builder().url(query).build();
  9.  
  10. httpClient.newCall(request).enqueue(new Callback() {
  11. @Override
  12. public void onFailure(Call call, IOException e) {
  13. }
  14. @Override
  15. public void onResponse(Call call, Response response) throws IOException {
  16. ResponseBody responseBody = response.body();
  17. if (!response.isSuccessful()) {
  18. throw new IOException("Error response " + response);
  19. }
  20. jsonResponse[0] = responseBody.string();
  21. Gson gson = new GsonBuilder().setLenient().serializeNulls().create();
  22. PlaceMapper mapper = gson.fromJson(jsonResponse[0], PlaceMapper.class);
  23. testClass test = new testClass();
  24. test.assignHours(mapper);
  25. }
  26. });
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement