[英]Google Place Picker on Android - limit area/radius
有沒有辦法限制用戶可以選擇他/她的位置的Google Place Picker區域?
像當前位置的半徑。
我不相信有文檔可以控制實際的Place Picker
意圖中的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
更改為您希望用戶從其位置選擇的最大距離。 希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.