2016-05-19 8 views

答えて

0

実際のPlace Pickerインテントで選択を制御するドキュメントはありませんが、あなたはそれを `onActivityResult 'で行うことができます。次に例を示します。

int PLACE_PICKER_REQUEST = 1; 
String toastMsg; 
Location selectedLocation = new Location(provider); 
Location currentLocation = new Location(provider); 
double maxDistance = 10; 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == PLACE_PICKER_REQUEST) { 
     if (resultCode == RESULT_OK) { 
      Place place = PlacePicker.getPlace(data, this); 

      selectedLocation.setLatitude(place.getLatLng().latitude); 
      selectedLocation.setLongitude(place.getLatLng().longitude); 
      if(selectedLocation.distanceTo(currentLocation) > maxDistance) { 
       toastMsg = "Invalid selection, please reselect your place"; 
       // Runs the selector again 
       PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); 
       startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); 
      } else { 
       // Result is fine 
       toastMsg = String.format("Place: %s", place.getName()); 
      } 
      Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); 
     } 
    } 
} 

あなたはユーザの選択は、その場所からになりたいの最大距離にmaxDistanceを変更することができます。それが役に立てば幸い!

関連する問題