我正在使用这个方法:
Places.GeoDataApi.getAutocompletePredictions(googleApiClient, query, bounds, AutocompleteFilter.create(null))
它需要一个包含东北和西南 LatLng 点的 LatLntBounds 对象作为查询的边界,但我不想提供任何对象。
尝试了null,但是得到了一个空指针异常尝试过:
LatLng southWest = new LatLng(85, -180);
LatLng northEast = new LatLng(-85, 180);
LatLngBounds bounds = new LatLngBounds(southWest, northEast);
但是得到了 IllegalArgumentException: southern latitude exceeds northern latitude (85.0 > -85.0)
那么我该如何:
a) 获取当前用户位置的合理范围
b) 获取世界边界
这样我就可以启动这个 API
它需要边界才能工作。只需创建它们即可。
import com.google.maps.android.SphericalUtil;
final double HEADING_NORTH_EAST = 45;
final double HEADING_SOUTH_WEST = 215;
final double diagonalBoundsSize = 1000; // 1km
LatLng centre = new LatLng(85, -180);
LatLng northEast = SphericalUtil.computeOffset(centre, diagonalBoundsSize / 2, HEADING_NORTH_EAST);
LatLng southWest = SphericalUtil.computeOffset(centre, diagonalBoundsSize / 2, HEADING_SOUTH_WEST);
LatLngBounds bounds = new LatLngBounds(southWest, northEast);
我是一名优秀的程序员,十分优秀!