【问题标题】:Android Google Service Place picker setLatLngBounds() not workingAndroid Google 服务地点选择器 setLatLngBounds() 不起作用
【发布时间】:2016-09-14 18:51:02
【问题描述】:

我在我的应用程序中使用 PlacePicker。突然间它的行为很糟糕。当它启动时,它指向 (0.0, 0.0) lat lng。 我不确定谷歌服务是否改变了一些东西。早些时候它工作得很好,因为从 3 天开始它就不能工作了。

我在这里做错了吗

这就是我启动 Activity 的方式。

private void launchPlacePicker(double latitude, double longitude) {
    try {
        showProgress(true);
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

        Log.d(TAG, " launchPlacePicker " + latitude + " " + longitude);

        builder.setLatLngBounds(MapUtils.getLatLngBounds(new LatLng((double) latitude, (double) longitude)));

        startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
    } catch (GooglePlayServicesRepairableException e) {
        showProgress(false);
        Log.e(TAG, "GooglePlayServicesRepairableException", e);
    } catch (GooglePlayServicesNotAvailableException e) {
        showProgress(false);
        Log.e(TAG, "GooglePlayServicesNotAvailableException", e);
    }
}

这就是我创建 LatLngBounds 的方式

public static LatLngBounds getLatLngBounds(LatLng center) {
    double radius = 100;
    LatLng southwest = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), 225);
    LatLng northeast = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), 45);
    return new LatLngBounds(southwest, northeast);
}

我尝试创建如下所示的 LatLngBounds,结果仍然相同。

public static LatLngBounds getLatLngBounds(LatLng center) {
    LatLngBounds.Builder builder = LatLngBounds.builder();
    builder.include(center);
    return builder.build();
}

谁能帮帮我

【问题讨论】:

    标签: android google-maps android-studio


    【解决方案1】:

    很遗憾,您将不得不等待 Google 在未来版本的 Google Play 服务中解决此问题。

    您的代码没有任何问题,Google Play 服务的最新更新导致 Place Picker UI 小部件出现一些严重问题。我首先注意到 setLatLngBounds() 方法不再适用于 Google Play Services 9.0.82。在 9.0.83 中,搜索图标消失了。

    请参阅我关于此问题的帖子:Android PlacePicker no longer has Search icon after updating to Google Play Services 9.0.83

    从 Google Maps API 错误和功能网站查看这些错误报告: Bug: Search Icon not visible in the latest play service update (Version:9.0.83) ----- Bug: Place Picker not showing search icon. ----- PlacePicker search icon is gone after updating to Google Play Services 9.0.83

    您可以通过调用 setLatLngBounds() 方法来解决这个问题。 PlacePicker 将默认为您当前的位置。我在我的应用程序中丢失了一些功能,但总比让最终用户尝试从大西洋回来的路上捏和平移要好。对我来说,丢失的搜索图标仍然是我的主要问题。

    【讨论】:

    • 地点选择器中的 setLatLngBounds() 问题应在当前版本的 Google Play 服务(6 月 26 日)中得到修复
    • 我知道这个问题很老,但我有类似的问题,PlacePicker 在启动时不默认为我的当前位置,它从之前选择的位置开始,我需要点击“我的位置”图标来获取标记移动到我的位置。任何想法如何在启动时默认强制 PlacePicker 到我当前的位置?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多