Guest User

Untitled

a guest
Jan 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public class CoordObject {
  2. private String lat;
  3. private String lon;
  4.  
  5. public CoordObject(
  6. String lat,
  7. String lon({
  8. this.lat =lat;
  9. this.lon =lon;
  10. }
  11.  
  12. public String getLat(){
  13. return lat;
  14. }
  15. public String getLon(){
  16. return lon;
  17. }
  18. }
  19.  
  20. public interface OwmInterface {
  21.  
  22. @GET("/data/2.5/weather")
  23. Call<CoordObject> getCoord(@Query("q") String zipCode,
  24. @Query("appid") String appId);
  25. }
  26.  
  27. final String BASE_URL = "https://api.openweathermap.org/";
  28. final String API_KEY_OWM = "xxxx";
  29.  
  30. Retrofit retrofit = new Retrofit.Builder()
  31. .baseUrl(BASE_URL)
  32. .addConverterFactory(GsonConverterFactory.create())
  33. .build();
  34. OwmInterface request = retrofit.create(OwmInterface.class);
  35.  
  36. Call<CoordObject> call = request.getCoord(
  37. "37421",
  38. API_KEY_OWM
  39. );
  40.  
  41. call.enqueue(new Callback<CoordObject>() {
  42. @Override
  43. public void onResponse(Call<CoordObject> call, Response<CoordObject> response){
  44. CoordObject coordObjectResponse = response.body();
  45. Toast.makeText(MainActivity.this, coordObjectResponse.getLat(), Toast.LENGTH_LONG).show();
  46. Toast.makeText(MainActivity.this, coordObjectResponse.getLon(), Toast.LENGTH_LONG).show();
  47. }
  48.  
  49. @Override
  50. public void onFailure(Call<CoordObject> call, Throwable t) {
  51. Toast.makeText(MainActivity.this, "failed" +t, Toast.LENGTH_SHORT).show();
  52. }
  53. });
Add Comment
Please, Sign In to add comment