1
//here is my code
public void performSearch() throws Exception {
        try {
            System.out.println("Perform Search ....");
            System.out.println("-------------------");
            HttpRequestFactory httpRequestFactory = createRequestFactory(transport);
            HttpRequest request = httpRequestFactory.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
            request.getUrl().put("key", API_KEY);
            request.getUrl().put("location", latitude + "," + longitude);
            request.getUrl().put("radius", 500);
            request.getUrl().put("sensor", "false");

            if (PRINT_AS_STRING) {
                System.out.println(request.execute().parseAsString());
                Log.d("--->",request.execute().parseAsString());
            } else {

                PlacesList places = request.execute().parseAs(PlacesList.class);
                System.out.println("STATUS = " + places.status);
                for (Place place : places.results) {
                    System.out.println(place);
                    Log.d("--->",place.toString());
                }
            }


        } catch (HttpResponseException e) {
            System.err.println(e.getResponse().parseAsString());
            throw e;
        }
    }
    public static HttpRequestFactory createRequestFactory(final HttpTransport transport) {

          return transport.createRequestFactory(new HttpRequestInitializer() {
           public void initialize(HttpRequest request) {
            GoogleHeaders headers = new GoogleHeaders();
            headers.setApplicationName("MyLocationHelper");
            request.setHeaders(headers);
           JsonHttpParser parser = null;
            parser.getJsonFactory();
           request.addParser(parser);
           }
        });
    }

我想开发一个应用程序来在地图上显示我当前的位置,而不是我想搜索附近的地方。在这个阶段,我可以在地图上绘制我当前的位置,但我无法从 google places api 获得响应。

performSearch() 方法调用 google places api。

4

1 回答 1

0

查看以下链接:-> 他们使用 HTTP 请求 + JSON 解析工作

在 Android 中解析 Google Places JSON 数据?

于 2012-10-11T05:48:38.270 回答