Android Google服务广告选择器setLatLngBounds()无效

时间:2016-05-18 10:32:53

标签: android google-maps android-studio

我在我的应用程序中使用PlacePicker。突然间,它表现得很糟糕。当它发射时指向(0.0,0.0)lat lng。 我不确定Google服务是否有所改变。早些时候它工作得很好,因为从3天起它无效。

我在这里做错了什么

这是我如何启动活动。

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();
}

可能有人帮助我

1 个答案:

答案 0 :(得分:14)

很遗憾,您将不得不等待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将默认为您当前的位置。我在我的应用程序中丢失了一些功能,但它比让最终用户试图从大西洋捏捏和平移更好。对我来说,丢失的搜索图标仍然是我的主要问题。