Places api 根据当前位置设置位置偏差

Places api set location biased based on current location

我正在使用新的 AutocompleteSupportFragment,因此用户可以搜索地点并选择他感兴趣的地点。我希望结果更接近于用户。我知道我可以设置 LocationBias,但它需要 RectangularBounds

我不知道矩形边界是什么,因为我只有当前位置 LatLng。我怎样才能达到预期的行为?

谢谢

您可以根据用户当前位置设置经纬度范围。以下是相同的示例。

private void setBounds(Location location, int mDistanceInMeters ){
    double latRadian = Math.toRadians(location.getLatitude());

    double degLatKm = 110.574235;
    double degLongKm = 110.572833 * Math.cos(latRadian);
    double deltaLat = mDistanceInMeters / 1000.0 / degLatKm;
    double deltaLong = mDistanceInMeters / 1000.0 / degLongKm;

    double minLat = location.getLatitude() - deltaLat;
    double minLong = location.getLongitude() - deltaLong;
    double maxLat = location.getLatitude() + deltaLat;
    double maxLong = location.getLongitude() + deltaLong;

    Log.d(TAG,"Min: "+Double.toString(minLat)+","+Double.toString(minLong));
    Log.d(TAG,"Max: "+Double.toString(maxLat)+","+Double.toString(maxLong));

    // Set up the adapter that will retrieve suggestions from the Places Geo Data API that cover
    // the entire world.
    mAdapter = new PlaceAutocompleteAdapter(this, android.R.layout.simple_list_item_1,
            mGoogleApiClient, new LatLngBounds(new LatLng(minLat, minLong), new LatLng(maxLat, maxLong)), null);
    mAutocompleteView.setAdapter(mAdapter);
}

如需进一步参考,您可以按照以下link