How to get Places.GeoDataApi.getAutocompletePredictions ONLY inside borders?

I use Places.GeoDataApi for Android, and I get different search results depending on the location of the device making the request. I need the results to be sequentially located within the borders. I do not see where this can be configured in the getAutocompletePredictions request. Is there something I can't see?

I get suggestions for autocomplete address / place using the GoogleApiClient and Places APIs via:

Places.GeoDataApi.getAutocompletePredictions()

This requires a GoogleApiClient object, a string for autocomplete, and a LatLngBounds object to limit the search range. Here is what my use looks like:

LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862));


GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .addApi(Places.GEO_DATA_API)
            .build();


PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(googleApiClient, "Starbucks", bounds, null);

Used version: com.google.android.gms: play-services-location: 8.3.0

: https://developers.google.com/places/android/autocomplete

+5
2

. 2018 Google , . getAutocompletePredictions() GeoDataClient boundsMode

public Task<AutocompletePredictionBufferResponse> getAutocompletePredictions (String query, LatLngBounds bounds, int boundsMode, AutocompleteFilter filter)

boundsMode - bounds. STRICT . BIAS, . , .

: https://developers.google.com/android/reference/com/google/android/gms/location/places/GeoDataClient

:

LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862));
GeoDataClient mGeoDataClient = Places.getGeoDataClient(getBaseContext());;

Task<AutocompletePredictionBufferResponse> results =
        mGeoDataClient.getAutocompletePredictions("Starbucks", bounds, GeoDataClient.BoundsMode.STRICT, null);

try {
    Tasks.await(results, 60, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException e) {
    e.printStackTrace();
}

try {
    AutocompletePredictionBufferResponse autocompletePredictions = results.getResult();

    Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
            + " predictions.");

    // Freeze the results immutable representation that can be stored safely.
    ArrayList<AutocompletePrediction> al = DataBufferUtils.freezeAndClose(autocompletePredictions);

    for (AutocompletePrediction p : al) {
        CharSequence cs = p.getFullText(new CharacterStyle() {
            @Override
            public void updateDrawState(TextPaint tp) {

            }
        });
        Log.i(TAG, cs.toString());
    }

} catch (RuntimeExecutionException e) {
    // If the query did not complete successfully return null
    Log.e(TAG, "Error getting autocomplete prediction API call", e);
}

, !

+3
+2

Source: https://habr.com/ru/post/1661725/


All Articles