org.apache.http.client.fluent破坏网址

时间:2016-11-10 16:30:46

标签: java google-maps google-maps-api-3 apache-httpclient-4.x

我有这样的网址https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=Belarus,Minsk,Kuprevicha,1/2&destinations=Belarus,Minsk,Kurchatova,8&key= {API_key},并且在浏览器中它正确计算距离:

{
   "destination_addresses" : [ "ул. Курчатова 8, Минск, Беларусь" ],
   "origin_addresses" : [
      "ул. Академика Купревича 1/2, Минск 220141, Беларусь"
   ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "24,5 км",
                  "value" : 24526
               },
               "duration" : {
                  "text" : "20 мин.",
                  "value" : 1196
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

但是当我使用org.apache.http.client.fluent.Request:

String req = Request.Get(uri).execute().handleResponse(UTF8_CONTENT_HANDLER);

执行此代码后,我得到了这样的结果:

{
   "destination_addresses" : [ "Minsk, Belarus" ],
   "origin_addresses" : [ "Minsk, Belarus" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "1 m",
                  "value" : 0
               },
               "duration" : {
                  "text" : "1 min",
                  "value" : 0
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

问题不是由apache Http Client发生的。 Google要求明确指定本地化。 Probaly用于英语本地化,它总是默认工作。如果您将&language=ru附加到网址,它将正常运行。