2017-05-06 109 views

回答

0

使用上进行此

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. 
} 

结果选择

@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. 
     } 
    } 
} 

链接https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically

0

从这里的浮动搜索示例的示例https://github.com/arimorty/floatingsearchview/blob/master/sample/src/main/java/com/arlib/floatingsearchviewdemo/data/DataHelper.java它为适配器提供了自定义筛选器。我相信你可以使用Google API的自动完成预测模型。

请在此处看样本 https://github.com/googlesamples/android-play-places/tree/master/PlaceCompleteAdapter他们如何使用Google API和ArrayAdapter的自定义过滤器。您可以将此示例中的自定义过滤器提供给floatingsearchview。