android - 从自动完成中选择地址后,适用于 Android 的 Google Place API map 指向错误位置 (0,0)

标签 android google-maps google-places-api

以前工作正常。我的意思是代码自几个月前就没有更改过。这就是现在发生的情况,在我从自动完成中点击一个地址后。

enter image description here

这就是我在选择位置后调用自动完成和 map 的方式。

private void openPlaceAutoComplete(){
    try {
        long touchTime = System.currentTimeMillis();
        if(touchTime - latestTouchedTime > BOUNCE_DELAY){
            latestTouchedTime = touchTime;
            Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                    .build(this.getActivity());
            startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST);
        }
    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
}

然后,在 ActivityResult 上

else if(requestCode == PLACE_AUTOCOMPLETE_REQUEST){
        if(resultCode == Activity.RESULT_OK){
            Place place = PlaceAutocomplete.getPlace(this.getFragmentBaseContext(), data);

            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            builder.setLatLngBounds(LocationHelper.getBoundsFromCenter(place.getLatLng(), PLACE_BOUND_RADIUS));
            try{
                startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);
            }catch (GooglePlayServicesNotAvailableException ex){
                ex.printStackTrace();
            }catch (GooglePlayServicesRepairableException ex){
                ex.printStackTrace();
            }
        }
    }

我已经确定这个地方不为空,并且它有一个不是 0,0 的 LatLng 对象,GetBoundsFromCenter 函数就是这样。

public static LatLngBounds getBoundsFromCenter(LatLng center, double radius){
    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);
}

最佳答案

不幸的是,这是地点选取器当前版本中的一个错误。参见 https://stackoverflow.com/a/37318013/2994了解更多信息。

关于android - 从自动完成中选择地址后,适用于 Android 的 Google Place API map 指向错误位置 (0,0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770687/

相关文章:

ios - Google Places API Framework 文件夹 iOS 中缺少某些类

android - 在 Android 版谷歌地图中查找最近的位置

android - Canvas : clear rect but keep the rest of the content

Android BLE 连接和断开快速读取 1 个特征。一些BLE设备在快速连接断开后停止广播

java - 如何从内存中的流式 zip 文件访问 zipEntry

javascript - 如何在 Google map API 上的标记周围添加圆圈

ios - 如何使Google map 的中心位于iPhone屏幕的底部中心?

google-maps - 谷歌自动完成分为单独的字段

javascript - 谷歌地图围绕搜索半径画圆

android - 如何在 Room 数据库中使用创建和打开回调