Google 将选择器放在 Android - 限制 area/radius

Google Place Picker on Android - limit area/radius

有没有办法限制用户可以选择 his/her 地点的 Google 地点选择器区域?

类似于当前位置的半径。

我认为没有文档可以控制实际 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 更改为您希望用户的选择距离他们的位置的最大距离。希望对您有所帮助!