简体   繁体   English

带有Floatingsearchview的Google地方信息自动完成功能

[英]Google Places Autocomplete with Floatingsearchview

Good Morning, I currently have a custom Google places autocomplete running with AutoCompleteTextView, but I need to implement it with the following library Floatingsearchview , But I can not find the way to do it, let's see if you can help me. 早上好,我目前有一个使用AutoCompleteTextView运行的自定义Google Places自动完成功能,但是我需要使用以下库Floatingsearchview来实现它,但是我找不到解决方法,让我们看看是否可以帮助我。

thanks 谢谢

Use this 用这个

try {
    Intent intent =
            new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                    .build(this);
    startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
} catch (GooglePlayServicesRepairableException e) {
    // TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
    // TODO: Handle the error.
}

Result on place selected 所选地点的结果

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(this, data);
            Log.i(TAG, "Place: " + place.getName());
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            // TODO: Handle the error.
            Log.i(TAG, status.getStatusMessage());

        } else if (resultCode == RESULT_CANCELED) {
            // The user canceled the operation.
        }
    }
}

Link https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically 以编程方式链接https://developers.google.com/places/android-api/autocomplete#get_place_predictions_program

From the sample of the floatingsearchview here https://github.com/arimorty/floatingsearchview/blob/master/sample/src/main/java/com/arlib/floatingsearchviewdemo/data/DataHelper.java it provide custom filter to the adapter. 从此处的floatsearchview示例中, https://github.com/arimorty/floatingsearchview/blob/master/sample/src/main/java/com/arlib/floatingsearchviewdemo/data/DataHelper.java为适配器提供了自定义过滤器。 I believe you can use AutocompletePrediction model from Google API. 我相信您可以使用Google API的AutocompletePrediction模型。

Please see sample here https://github.com/googlesamples/android-play-places/tree/master/PlaceCompleteAdapter How they use custom filter with Google API and ArrayAdapter. 请在此处查看示例https://github.com/googlesamples/android-play-places/tree/master/PlaceCompleteAdapter如何将自定义过滤器与Google API和ArrayAdapter一起使用。 You can just provide the custom filter in this sample to floatingsearchview. 您可以仅在此示例中将自定义过滤器提供给floatsearchview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM