Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CoordObject {
- private String lat;
- private String lon;
- public CoordObject(
- String lat,
- String lon({
- this.lat =lat;
- this.lon =lon;
- }
- public String getLat(){
- return lat;
- }
- public String getLon(){
- return lon;
- }
- }
- public interface OwmInterface {
- @GET("/data/2.5/weather")
- Call<CoordObject> getCoord(@Query("q") String zipCode,
- @Query("appid") String appId);
- }
- final String BASE_URL = "https://api.openweathermap.org/";
- final String API_KEY_OWM = "xxxx";
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl(BASE_URL)
- .addConverterFactory(GsonConverterFactory.create())
- .build();
- OwmInterface request = retrofit.create(OwmInterface.class);
- Call<CoordObject> call = request.getCoord(
- "37421",
- API_KEY_OWM
- );
- call.enqueue(new Callback<CoordObject>() {
- @Override
- public void onResponse(Call<CoordObject> call, Response<CoordObject> response){
- CoordObject coordObjectResponse = response.body();
- Toast.makeText(MainActivity.this, coordObjectResponse.getLat(), Toast.LENGTH_LONG).show();
- Toast.makeText(MainActivity.this, coordObjectResponse.getLon(), Toast.LENGTH_LONG).show();
- }
- @Override
- public void onFailure(Call<CoordObject> call, Throwable t) {
- Toast.makeText(MainActivity.this, "failed" +t, Toast.LENGTH_SHORT).show();
- }
- });
Add Comment
Please, Sign In to add comment