-2
我使用Volley庫來執行請求。Android Volley:錯誤的URL編碼
當我向Google Maps v3發出地址地址解析的簡單請求時,我收到INVALID_REQUEST或400錯誤。在像URL發生
問題: http://maps.googleapis.com/maps/api/geocode/json?address=52072,Aachen-Horbach GZG &區域=申&傳感器=假
http://maps.googleapis.com/maps/api/geocode/json?address=362 35,阿貝爾塔米-上布拉特納&區域= ITA &傳感器=假
當我使用相同的與Apache DefaultHttpClient
的網址,一切工作正常。
如何我傳遞的網址:
StringBuilder addressDepartureUrl = new StringBuilder();
if (order.getDepartureAddress().getStreet()!=null && !order.getDepartureAddress().getStreet().equalsIgnoreCase(""))
addressDepartureUrl.append(order.getDepartureAddress().getStreet() + ", ");
if (order.getDepartureAddress().getHouseNumber()!=null && ! order.getDepartureAddress().getHouseNumber().equalsIgnoreCase(""))
addressDepartureUrl.append(order.getDepartureAddress().getHouseNumber() + ", ");
if (order.getDepartureAddress().getZipCode()!=null && !order.getDepartureAddress().getZipCode().equalsIgnoreCase(""))
addressDepartureUrl.append(order.getDepartureAddress().getZipCode() + ",");
if (order.getDepartureAddress().getCity()!=null && !order.getDepartureAddress().getCity().equalsIgnoreCase(""))
addressDepartureUrl.append(order.getDepartureAddress().getCity());
if (order.getDepartureAddress().getCountryCode()!=null && !order.getDepartureAddress().getCountryCode().equalsIgnoreCase(""))
addressDepartureUrl.append("®ion="+order.getDepartureAddress().getCountryCode());
addressDepartureUrl.append("&sensor=false");
String finalDepartureUrl = Constants.URL_GEOCODING + addressDepartureUrl.toString();
RequestQueue queue = Volley.newRequestQueue(getActivity());
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url.toString(), null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG + " getGeocodingResults response", response.toString());
Log.i(TAG + " flag", Integer.toString(flag));
volleyResponse = response;
mVolleyResponse.onDataReceived(flag, response, order);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
// hide the progress dialog
}
});
queue.add(jsonObjReq);
How can I receive the same results as with the help of `Apache` library ?
爲什麼濫用沒有解釋? –