Is there a way to limit Google Place Picker area that user is able to pick his/her place?
Something like radius from current location.
I don't believe there is documentation to control the selection in the actual Place Picker
intent, but you could do it in the `onActivityResult. Here is an example:
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();
}
}
}
You can change maxDistance
to the maximum distance you want the user's selection to be from their location. Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With