Newer
Older
CosmosClient / app / src / main / java / com / example / cosmosclient / retrofitsample / GisActivity.java
  1. package com.example.cosmosclient.retrofitsample;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.util.Log;
  6.  
  7. import com.example.cosmosclient.R;
  8. import com.fasterxml.jackson.annotation.JsonTypeInfo;
  9. import com.fasterxml.jackson.core.type.TypeReference;
  10. import com.fasterxml.jackson.databind.ObjectMapper;
  11.  
  12. import java.io.IOException;
  13. import java.io.InputStream;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16.  
  17. import retrofit2.Call;
  18. import retrofit2.Callback;
  19. import retrofit2.Response;
  20. import retrofit2.Retrofit;
  21. import retrofit2.converter.jackson.JacksonConverterFactory;
  22.  
  23. public class GisActivity extends AppCompatActivity{
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_gis);
  28.  
  29. Retrofit retrofit = new Retrofit.Builder()
  30. .baseUrl("http://cyberjapandata2.gsi.go.jp/")
  31. .addConverterFactory(JacksonConverterFactory.create())
  32. .build();
  33. GisService service = retrofit.create(GisService.class);
  34. // ObjectMapper mapper = new ObjectMapper();
  35. // try {
  36. // ArrayList<Ele> list = mapper.readValue((InputStream) service.listEles(140.08531, 36.103543, "JSON"), new TypeReference<ArrayList<Ele>>() {});
  37. // } catch (IOException e) {
  38. // e.printStackTrace();
  39. // }
  40.  
  41. Call<Ele> call = service.listEles(140.08531, 36.103543, "JSON");
  42. call.enqueue(new Callback<Ele>() {
  43. @Override
  44. public void onResponse(Call<Ele> call, Response<Ele> response) {
  45. if (response.isSuccessful()) {
  46. Ele result = response.body();
  47. System.out.println(result.elevation);
  48. System.out.println(result.hsrc);
  49. }
  50. }
  51.  
  52. @Override
  53. public void onFailure(Call<Ele> call, Throwable t) {
  54. t.printStackTrace();
  55. }
  56.  
  57. });
  58. }
  59.  
  60. }