Pregunta

I'm doing an appplication on Android, and I have to start Google Navigation (with longitude and latitude). All I've got is an adress (here an example : " * * * "). From that I have to get the coordinates.

So I use Google Geocoding, and did a HTTP request from Java :

public class LocationInfo extends AsyncTask<String, Void, JSONObject> {
    @Override
    protected JSONObject doInBackground(String... adresse) {
        HttpGet httpGet = new HttpGet(
                "https://maps.googleapis.com/maps/api/geocode/json"
                + "?address=" + adresse 
                + "&sensor=true");
        HttpClient client = new DefaultHttpClient();
        HttpResponse response;
        StringBuilder stringBuilder = new StringBuilder();

        try {
            response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();
            InputStream stream = entity.getContent();
            int b;
            while ((b = stream.read()) != -1) {
                stringBuilder.append((char) b);
            }
        } catch (ClientProtocolException e) {
        } catch (IOException e) {
        }

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = new JSONObject(stringBuilder.toString());
        } catch (JSONException e) {
        }
        return jsonObject;
    }
}

With this request I have the result ZERO_RESULT, but when I try it on my browser, I have a normal result.

It worked fine for a few hours on my devices, and after, i had this issue... Anyone have an answer ? Thanks !

¿Fue útil?

Solución

adresse is not a string here but a vararg. You probably want to pick the first string in there so use adresse[0] here.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top