适用于Android地图的Google Place API指向错误位置(0,0)从自动填充中选择地址后

时间:2016-06-12 04:17:46

标签: android google-maps google-places-api

以前运作良好。我的意思是几个月前代码没有改变。这是我从自动完成点击地址后现在发生的事情。

enter image description here

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

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

我确保该地方不为空,并且它的LatLng对象不是0,0而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);
}

1 个答案:

答案 0 :(得分:2)

不幸的是,这是Place Picker当前版本中的一个错误。有关详细信息,请参阅https://stackoverflow.com/a/37318013/2994