Android GooglePlacesAPI-V2-Autocomplete不会显示所有的位置结果

Android GooglePlacesAPI-V2-Autocomplete不会显示所有的位置结果,android,google-places-api,google-maps-api-2,Android,Google Places Api,Google Maps Api 2,我试图遵循android文档,但它并没有向我展示所有关于这些地方的建议。例如,如果我编写集群Z,这不会显示任何建议。确切地说,我想要的是,如果我输入位置X2,它应该返回X1,X2本身,X3,X4,X5,因为我被这些位置包围着。我错过了什么 private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place"; private static final String TYPE_AUTOC

我试图遵循android文档,但它并没有向我展示所有关于这些地方的建议。例如,如果我编写集群Z,这不会显示任何建议。确切地说,我想要的是,如果我输入位置X2,它应该返回X1,X2本身,X3,X4,X5,因为我被这些位置包围着。我错过了什么

private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place";
private static final String TYPE_AUTOCOMPLETE = "/autocomplete";
private static final String OUT_JSON = "/json";
ArrayList<String> resultList = null;
//API KEY = xxxxxxxxxxxxxxxxxxx; // Enter Your Key

private ArrayList<String> autocomplete(String input) {

    HttpURLConnection conn = null;
    StringBuilder jsonResults = new StringBuilder();
    try {
        StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
        sb.append("?key=" + "Enter Your Key");
        sb.append("&components=country:myCountry");
        sb.append("&input=" + URLEncoder.encode(input, "utf8"));

        URL url = new URL(sb.toString());
        conn = (HttpURLConnection) url.openConnection();
        InputStreamReader in = new InputStreamReader(conn.getInputStream());

        // Load the results into a StringBuilder
        int read;
        char[] buff = new char[1024];
        while ((read = in.read(buff)) != -1) {
            jsonResults.append(buff, 0, read);
        }
    } catch (MalformedURLException e) {
        // Log.e(LOG_TAG, "Error processing Places API URL", e);
        return resultList;
    } catch (IOException e) {
        // Log.e(LOG_TAG, "Error connecting to Places API", e);
        return resultList;
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }

    try {
        // Create a JSON object hierarchy from the results
        JSONObject jsonObj = new JSONObject(jsonResults.toString());
        JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");

        // Extract the Place descriptions from the results
        resultList = new ArrayList<String>(predsJsonArray.length());
        for (int i = 0; i < predsJsonArray.length(); i++) {
            resultList.add(predsJsonArray.getJSONObject(i).getString("description"));

        }
    } catch (JSONException e) {
        //Log.e(LOG_TAG, "Cannot process JSON results", e);
    }

    Log.v("returnResult",""+resultList.toString());
    return resultList;
}

如果您想显示Google地图搜索框中显示的所有结果,请尝试使用Google搜索框而不是自动完成。如果您想用一个库方法调用替换所有代码,您可以查看披露:我是开发人员。等价物如下所示:

Places.autocomplete(Params.create().query(input)).getResult()
您还可以查看小部件,它为您提供一切,并提供用户选择的功能

<net.sf.sprockets.widget.GooglePlaceAutoComplete
    android:id="@+id/place"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

你能给我在你的浏览器中放置键或用键检查url吗?。是正确的url和键吗?我最近集成了它,它工作正常,你还需要传递位置以获得准确的结果。遵循此教程可能会对你有所帮助。我想要完美的结果,我添加了位置、半径以获得更精确的结果,但没有任何帮助。@droid:我遵循了那个教程。