2017-05-06 50 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。

相關問題