【问题标题】:Can I restrict PlacePicker control of Android to a Particular country?我可以将 Android 的 PlacePicker 控制限制在特定国家/地区吗?
【发布时间】:2017-06-21 10:18:20
【问题描述】:

我正在使用 Android 提供的最新 Place Picker 控件。它真的很容易使用。

现在,问题是:

  1. 我可以将搜索区域限制在印度吗?

  2. 我可以更改 PlacePicker 控件中的默认标记图标吗?

注意:我没有使用任何 MapView 或 Fragment 来显示任何地图。我正在使用 PlacePicker 而不是 GoogleMap。

【问题讨论】:

    标签: android google-maps-api-3 google-maps-markers gmsplacepicker


    【解决方案1】:
       public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {
                Place place = PlacePicker.getPlace(mActivity, data);
                Log.d(TAG, "onActivityResult: " + place.getAddress());
                if (place.getAddress() != null) {
                    // ask for geolocation data
                    Geocoder gcd = new Geocoder(mActivity, Locale.getDefault());
    
                    try {
                        addresses = gcd.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
    
    
                    if (addresses.size() > 0) {
                        if (addresses.get(0).getCountryCode().equalsIgnoreCase(getString(R.string.india))) {
                            //write the code here
                        } else {
                            Toast.makeText(mActivity, "Invalid places", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            }
        }
    }
    

    【讨论】:

    • 不是一种可靠的方法,只是一种解决方案,因此它可以在某种程度上发挥作用。
    猜你喜欢
    • 1970-01-01
    • 2016-06-22
    • 2017-08-05
    • 2015-09-03
    • 1970-01-01
    • 2012-01-06
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多