Question

I'm using google place autocompletetextview, I followed the tutorial and it works just fine. By now I get a list of suggested result but there is no filter for cities, and most of the suggestion are streets name.

My question if there's a way to filter the street names so the result list will include only cities.

Heres my StringBuilder code:

    HttpURLConnection conn = null;
    StringBuilder jsonResults = new StringBuilder();
    try {
        StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
        sb.append("?sensor=false&key=" + API_KEY);
        sb.append("&components=country:il");
        sb.append("&input=" + URLEncoder.encode(input, "utf8"));
Was it helpful?

Solution

Take a look at the (cities) type collection in the documentation.

OTHER TIPS

Google Api for get cities details.

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Chen&types=(cities)&key={Your_ApiKey}

So Insert the below line in your code

sb.append("&types=(cities)");

Full code:

 StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
            sb.append("?sensor=false&key=" + API_KEY);
            sb.append("&components=country:il");
            sb.append("&types=(cities)");
            sb.append("&input=" + URLEncoder.encode(input, "utf8"));

Happy Coding :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top