Android上的Google Place Picker-限制区域/半径

Android上的Google Place Picker-限制区域/半径,android,google-places-api,Android,Google Places Api,有没有办法限制用户可以选择他/她的位置的谷歌位置选择器区域 类似于当前位置的半径。我不相信有文档可以控制实际的位置选择器的选择,但您可以在“onActivityResult”中执行。以下是一个例子: int PLACE_PICKER_REQUEST = 1; String toastMsg; Location selectedLocation = new Location(provider); Location currentLocation = new Location(provider);

有没有办法限制用户可以选择他/她的位置的谷歌位置选择器区域


类似于当前位置的半径。

我不相信有文档可以控制实际的
位置选择器的选择,但您可以在“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
更改为希望用户的选择距离其所在位置的最大距离。希望有帮助

当你说“谷歌地点选择器”时,你是指
标记器吗?不是-我是指来自PlacesAPI的地点选择器-