2017-09-16 10 views
0

私はアンドロイドのアプリでUberの運賃見積もりを表示しようとしています.APIからデータを読み込むためにretrofitを使用しています。ステータスコード= 200も受け取っています(これはuberのdocs)しかし、私が選んだコーディネイトに関係なく、私の価格表は常にゼロです。Uber apiがnullを返す

**retrofit interface class.** 

    public interface PriceEstimate { 

    @GET("/v1.2/estimates/price") 
    Call<Prices> getEstimate(@Header("Authorization") String authToken, 
           @Query("start_latitude") float start_latitude, 
           @Query("start_longitude") float start_longitude, 
           @Query("end_latitude") float stop_latitude, 
           @Query("end_longitude") float stop_longitude); 
} 

価格クラス:

public class Prices { 
    public List<PriceModel> prices; 
    private Map<String, Object> additionalProperties = new HashMap<String, Object>(); 
public List<PriceModel> getPrices() { 
    return prices; 
} 

public void setPrices(List<PriceModel> prices) { 
    this.prices = prices; 
} 

public Map<String, Object> getAdditionalProperties() { 
    return this.additionalProperties; 
} 

public void setAdditionalProperty(String name, Object value) { 
    this.additionalProperties.put(name, value); 
} 

} 

価格モデル:

public class PriceModel { 

    private String localizedDisplayName; 
    private Double distance; 
    private String displayName; 
    private String productId; 
    private Object highEstimate; 
    private Object lowEstimate; 
    private Integer duration; 
    private String estimate; 
    private Object currencyCode; 
    private Map<String, Object> additionalProperties = new HashMap<String, Object>(); 

    public String getLocalizedDisplayName() { 
     return localizedDisplayName; 
    } 

    public void setLocalizedDisplayName(String localizedDisplayName) { 
     this.localizedDisplayName = localizedDisplayName; 
    } 

    public Double getDistance() { 
     return distance; 
    } 

    public void setDistance(Double distance) { 
     this.distance = distance; 
    } 

    public String getDisplayName() { 
     return displayName; 
    } 

    public void setDisplayName(String displayName) { 
     this.displayName = displayName; 
    } 

    public String getProductId() { 
     return productId; 
    } 

    public void setProductId(String productId) { 
     this.productId = productId; 
    } 

    public Object getHighEstimate() { 
     return highEstimate; 
    } 

    public void setHighEstimate(Object highEstimate) { 
     this.highEstimate = highEstimate; 
    } 

    public Object getLowEstimate() { 
     return lowEstimate; 
    } 

    public void setLowEstimate(Object lowEstimate) { 
     this.lowEstimate = lowEstimate; 
    } 

    public Integer getDuration() { 
     return duration; 
    } 

    public void setDuration(Integer duration) { 
     this.duration = duration; 
    } 

    public String getEstimate() { 
     return estimate; 
    } 

    public void setEstimate(String estimate) { 
     this.estimate = estimate; 
    } 

    public Object getCurrencyCode() { 
     return currencyCode; 
    } 

    public void setCurrencyCode(Object currencyCode) { 
     this.currencyCode = currencyCode; 
    } 

    public Map<String, Object> getAdditionalProperties() { 
     return this.additionalProperties; 
    } 

    public void setAdditionalProperty(String name, Object value) { 
     this.additionalProperties.put(name, value); 
    } 


} 

活動

submit.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       Retrofit retrofit=new Retrofit.Builder() 
         .baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()) 
         .build(); 
       PriceEstimate service=retrofit.create(PriceEstimate.class); 
       Call<Prices> call=service.getEstimate(token,pick_lats,pick_Long,drop_lats,drop_Long);//token=server_token 
       call.enqueue(new Callback<Prices>() { 
        @Override 
        public void onResponse(Call<Prices> call, Response<Prices> response) { 
         List<PriceModel> prices; 
         prices=response.body().getPrices();//this is null always 

        } 

        @Override 
        public void onFailure(Call<Prices> call, Throwable t) { 
         Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show(); 
        } 
       }); 
      } 
     }); 

完全なJSONログ

{ 
    "body":{ 
     "additionalProperties":{ 

     }, 
     "prices":[ 

     ] 
    }, 
    "rawResponse":{ 
     "body":{ 
     "contentLength":13, 
     "contentType":{ 
      "mediaType":"application/json", 
      "subtype":"json", 
      "type":"application" 
     } 
     }, 
     "code":200, 
     "handshake":{ 
     "cipherSuite":{ 
      "javaName":"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" 
     }, 
     "localCertificates":[ 

     ], 
     "peerCertificates":[ 
      { 
       "type":"X.509" 
      }, 
      { 
       "type":"X.509" 
      }, 
      { 
       "type":"X.509" 
      } 
     ], 
     "tlsVersion":"TLS_1_2" 
     }, 
     "headers":{ 
     "namesAndValues":[ 
      "Server", 
      "nginx", 
      "Date", 
      "Sat, 16 Sep 2017 16:25:39 GMT", 
      "Content-Type", 
      "application/json", 
      "Content-Length", 
      "13", 
      "Connection", 
      "keep-alive", 
      "Content-Geo-System", 
      "wgs-84", 
      "Content-Language", 
      "en", 
      "Etag", 
      "\"170e362581d1816dbaf082a7ac196cba26bbc4f7\"", 
      "X-Uber-App", 
      "uberex-nonsandbox", 
      "X-Uber-App", 
      "optimus", 
      "Strict-Transport-Security", 
      "max-age\u003d604800", 
      "X-Content-Type-Options", 
      "nosniff", 
      "X-XSS-Protection", 
      "1; mode\u003dblock", 
      "Strict-Transport-Security", 
      "max-age\u003d2592000", 
      "X-Frame-Options", 
      "SAMEORIGIN", 
      "Cache-Control", 
      "max-age\u003d0" 
     ] 
     }, 
     "message":"OK", 
     "networkResponse":{ 
     "code":200, 
     "handshake":{ 
      "cipherSuite":{ 
       "javaName":"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" 
      }, 
      "localCertificates":[ 

      ], 
      "peerCertificates":[ 
       { 
        "type":"X.509" 
       }, 
       { 
        "type":"X.509" 
       }, 
       { 
        "type":"X.509" 
       } 
      ], 
      "tlsVersion":"TLS_1_2" 
     }, 
     "headers":{ 
      "namesAndValues":[ 
       "Server", 
       "nginx", 
       "Date", 
       "Sat, 16 Sep 2017 16:25:39 GMT", 
       "Content-Type", 
       "application/json", 
       "Content-Length", 
       "13", 
       "Connection", 
       "keep-alive", 
       "Content-Geo-System", 
       "wgs-84", 
       "Content-Language", 
       "en", 
       "Etag", 
       "\"170e362581d1816dbaf082a7ac196cba26bbc4f7\"", 
       "X-Uber-App", 
       "uberex-nonsandbox", 
       "X-Uber-App", 
       "optimus", 
       "Strict-Transport-Security", 
       "max-age\u003d604800", 
       "X-Content-Type-Options", 
       "nosniff", 
       "X-XSS-Protection", 
       "1; mode\u003dblock", 
       "Strict-Transport-Security", 
       "max-age\u003d2592000", 
       "X-Frame-Options", 
       "SAMEORIGIN", 
       "Cache-Control", 
       "max-age\u003d0" 
      ] 
     }, 
     "message":"OK", 
     "protocol":"HTTP_1_1", 
     "receivedResponseAtMillis":1505576817826, 
     "request":{ 
      "cacheControl":{ 
       "immutable":false, 
       "isPrivate":false, 
       "isPublic":false, 
       "maxAgeSeconds":-1, 
       "maxStaleSeconds":-1, 
       "minFreshSeconds":-1, 
       "mustRevalidate":false, 
       "noCache":false, 
       "noStore":false, 
       "noTransform":false, 
       "onlyIfCached":false, 
       "sMaxAgeSeconds":-1 
      }, 
      "headers":{ 
       "namesAndValues":[ 
        "Authorization", 
        "Token wegHf8ihFOzW2TI7pefdVz7xkst_cC3oXLvMhtmW", 
        "Host", 
        "api.uber.com", 
        "Connection", 
        "Keep-Alive", 
        "Accept-Encoding", 
        "gzip", 
        "User-Agent", 
        "okhttp/3.8.0" 
       ] 
      }, 
      "method":"GET", 
      "tag":{ 
       "headers":{ 
        "namesAndValues":[ 
        "Authorization", 
        "Token wegHf8ihFOzW2TI7pefdVz7xkst_cC3oXLvMhtmW" 
        ] 
       }, 
       "method":"GET", 
       "url":{ 
        "host":"api.uber.com", 
        "password":"", 
        "pathSegments":[ 
        "v1.2", 
        "estimates", 
        "price" 
        ], 
        "port":443, 
        "queryNamesAndValues":[ 
        "start_latitude", 
        "17.368908", 
        "start_longitude", 
        "17.368908", 
        "end_latitude", 
        "17.413828", 
        "end_longitude", 
        "17.413828" 
        ], 
        "scheme":"https", 
        "url":"https://api.uber.com/v1.2/estimates/price?start_latitude\u003d17.368908\u0026start_longitude\u003d17.368908\u0026end_latitude\u003d17.413828\u0026end_longitude\u003d17.413828", 
        "username":"" 
       } 
      }, 
      "url":{ 
       "host":"api.uber.com", 
       "password":"", 
       "pathSegments":[ 
        "v1.2", 
        "estimates", 
        "price" 
       ], 
       "port":443, 
       "queryNamesAndValues":[ 
        "start_latitude", 
        "17.368908", 
        "start_longitude", 
        "17.368908", 
        "end_latitude", 
        "17.413828", 
        "end_longitude", 
        "17.413828" 
       ], 
       "scheme":"https", 
       "url":"https://api.uber.com/v1.2/estimates/price?start_latitude\u003d17.368908\u0026start_longitude\u003d17.368908\u0026end_latitude\u003d17.413828\u0026end_longitude\u003d17.413828", 
       "username":"" 
      } 
     }, 
     "sentRequestAtMillis":1505576817197 
     }, 
     "protocol":"HTTP_1_1", 
     "receivedResponseAtMillis":1505576817826, 
     "request":{ 
     "headers":{ 
      "namesAndValues":[ 
       "Authorization", 
       "Token wegHf8ihFOzW2TI7pefdVz7xkst_cC3oXLvMhtmW" 
      ] 
     }, 
     "method":"GET", 
     "url":{ 
      "host":"api.uber.com", 
      "password":"", 
      "pathSegments":[ 
       "v1.2", 
       "estimates", 
       "price" 
      ], 
      "port":443, 
      "queryNamesAndValues":[ 
       "start_latitude", 
       "17.368908", 
       "start_longitude", 
       "17.368908", 
       "end_latitude", 
       "17.413828", 
       "end_longitude", 
       "17.413828" 
      ], 
      "scheme":"https", 
      "url":"https://api.uber.com/v1.2/estimates/price?start_latitude\u003d17.368908\u0026start_longitude\u003d17.368908\u0026end_latitude\u003d17.413828\u0026end_longitude\u003d17.413828", 
      "username":"" 
     } 
+1

'response.body()'は何を返しますか? – joao86

+0

私はデバッガを使用してボディオブジェクトの値をチェックするときにこれらを表示します------- additionalProperties = {HashMap @ 5000} size = 0 prices = {ArrayList @ 5001} size = 0 shadow $ _klass_ = {Class @ 4859} "class com.sohail.farecompare.Prices" 影$ _monitor_ = -2006322734 –

+0

ログキャットでjsonの応答を記録し、ここに投稿する –

答えて

0

私は自分の間違いを見つけましたが、将来ここで誰かを助けることができるようにここで共有しています。

私は経度の値を渡して緯度を誤って座標を渡していましたが、その逆もありました。私の後ろの時間を無駄にした後、本当に馬鹿だと感じる

関連する問題