Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict autocomplete results by setBoundsBias

Tags:

I am using setBoundsBias for Restrict autocomplete results in google map autocompletePlace, But the result contains places out of range. what is the problem ?

{

final int PLACE_AUTOCOMPLETE_REQUEST_CODE = 1;

 AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
                        .setCountry("IR")
                        .build();
                try {
                    Intent intent =
                            new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                                    .setBoundsBias(new LatLngBounds(new LatLng(38.051183, 46.211586),
                                                new LatLng(38.132784, 46.392860)))
                                    .setFilter(typeFilter)
                                    .build(MainActivity.this);
                    startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
                    overridePendingTransition(R.anim.fadein, R.anim.fadeout);

                } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
                    e.fillInStackTrace();
                }

}
like image 851
tohidmahmoudvand Avatar asked May 08 '17 10:05

tohidmahmoudvand


1 Answers

The bounds bias is not a strict filter, so there is no guarantee that places outside of the area are not included. Currently the Places API for Android doesn't have an option to apply strict bounds.

A couple of months ago the ability to apply the strict bounds filter was introduced in Places API web service and in places library of Maps JavaScript API. You can refer to this feature request in the issue tracker:

https://buganizer.corp.google.com/issues/35826806

However, the Places API for Android and Places API for iOS are still missing this feature.

I have created a feature request in the public issue tracker for Android:

https://issuetracker.google.com/issues/38188994

and for iOS:

https://issuetracker.google.com/issues/38188941

Please star these feature requests to add your vote and subscribe to updates from Google.

Hopefully, one day they will implement this feature.

like image 81
xomena Avatar answered Sep 24 '22 09:09

xomena