【问题标题】:Trying to get place from place picker but it open and closes试图从地点选择器中找到位置,但它会打开和关闭
【发布时间】:2019-03-08 05:21:03
【问题描述】:

我正在集成地点选择器,但我已经启用了地点 api,但它会立即打开和关闭。

我已创建 api 密钥并将其放在清单文件中 仍然无法正常工作。在我的 logcat 中它给了我错误

2019-03-08 10:31:41.640 2837-2358/? E/Places:您的应用似乎没有启用 Places API for Android。有关详细信息,请参阅https://developers.google.com/places/android/signup。 2019-03-08 10:31:41.651 4713-4713/? E/Places:Place Picker 由于 PLACES_API_ACCESS_NOT_CONFIGURED 而关闭 2019-03-08 10:31:41.775 2837-2358/? E/Places:您的应用似乎没有启用 Places API for Android。有关详细信息,请参阅https://developers.google.com/places/android/signup。 2019-03-08 10:31:41.776 2837-2358/? E/AsyncOperation: serviceID=65, operation=SearchPlaces OperationException[状态{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED,分辨率=null}]

这是我的代码

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="key" />


 @SuppressLint("MissingPermission")
    private void showPlacePicker() {
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
        try {
            startActivityForResult(builder.build(NewOrderActivity.this), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {

            if (resultCode == RESULT_OK) {
                Place place = PlacePicker.getPlace(data, NewOrderActivity.this);
                edt_pickup_address.setText(place.getAddress());
                Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
                try {
                    List<Address> listAddresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
                    if (null != listAddresses && listAddresses.size() > 0) {
                      /*  post_area = listAddresses.get(0).getSubLocality();
                        post_city = listAddresses.get(0).getSubAdminArea();
                        post_state = listAddresses.get(0).getAdminArea();*/

                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }


                String place_phone_number = "" + place.getPhoneNumber();
                if (!TextUtils.isEmpty(place_phone_number)) {
                    String[] phone_number = place_phone_number.split(" ");
                    String s = "";
                    for (int i = 0; i < phone_number.length; i++) {
                        if (i != 0) {
                            s = s + phone_number[i];
                        }
                    }
//                    et_contact_no_add_company.setText(s);
                } else {
//                    et_contact_no_add_company.setText("");
                }
                if (place.getWebsiteUri() != null) {
//                    et_website_add_company.setText("" + place.getWebsiteUri());
                } else {
//                    et_website_add_company.setText("");
                }
            }
        }
    }

【问题讨论】:

标签: android google-places-api gmsplacepicker


【解决方案1】:

根据谷歌新更新Place Picker Deprecate,以后将不再可用,这里是官方声明

弃用通知:地点选择器

注意:地点选择器(Android、iOS)自 2019 年 1 月 29 日起弃用。此功能将于 2019 年 7 月 29 日关闭, 并且在该日期之后将不再可用。要继续使用 Place Picker 与 Places SDK for iOS v.2.7.0 通过弃用 期间,请勿禁用 Places SDK for iOS。阅读迁移 指南(Android、iOS)以了解更多信息。

所以,对方可以使用Place Autocomplete

但在新的 Place API 中存在一些限制,您必须启用 Billing 帐户才能使用 Place Autocomplete。

提醒:要使用 Places API,您必须获取 API 密钥并且必须 启用计费。您可以在获得 API 密钥时启用计费(请参阅 快速指南)或作为单独的流程(请参阅使用情况和计费)。

替代解决方案:使用Geocoder 从地名中获取latLong

【讨论】:

    【解决方案2】:

    弃用通知:Android 版 Places SDK 的 Google Play 服务版本

    请参考此链接

    https://developers.google.com/places/android-sdk/autocomplete

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2016-09-20
      • 1970-01-01
      相关资源
      最近更新 更多