0

我有这个代码:

package sig;

import org.json.JSONObject;

public class MyService extends java.lang.Object{

    public JSONObject getLocationInfo( double lat, double lng) {

        HttpGet httpGet = new HTTP("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false");
        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) {
            e.printStackTrace();
        }
        return jsonObject;
    }
}

但它错误HttpGet,我应该使用什么库才能使用HttpGet,谢谢!

4

1 回答 1

0

使用 httpcomponents-client jar。

它的 Maven 条目为:

<dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.1.1</version>
    </dependency>
于 2013-10-06T08:01:01.487 回答