androidgoogle-mapstransportplaceautocompletefragment

How to restrict PlaceAutocompleteFragment to only show public transport stations? Android


I am in process of making a public transport app and for that cause I want to restrict my PlaceAutocompleteFragment to only Tram, Bus and Train Stations within my city.

So far I have implemented google map, place autocomplete fragment and restricted it to my country and city. This is part of my code:

    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setBoundsBias(new LatLngBounds(
            new LatLng(45.707197, 15.665182),
            new LatLng(45.913958, 16.277670)));

    AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
            .setCountry("HR")
            .build();

    autocompleteFragment.setFilter(typeFilter);

I looked into filters and I couldn't find anything like public transport stations. Thanks for help


Solution

  • AutocompleteFilter only provides a few types, as you already probably know. I think you have two options:

    1) Use Place Autocomplete Web Service, I believe you will be able to filter the returned result in the URL, you will have to try.
    2) Google provides tables for the place types here. The establishment type that you need is available in Table 1, which corresponds to Place Search, which is also a web service.

    So for both, you will have to make an HTTP request. But unfortunately, you cannot filter them using AutocompleteFilter. But for the sake of trying:

    AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
                    .setTypeFilter(Place.TYPE_BANK)
                    .build();
    

    And it doesn't work either. So your possible option is to use the Web Service.