如何为 Google Places API 的 getAutocompletePredictions() 方法提供合理的默认范围?
How to provide reasonable default bounds for Google Places API's getAutocompletePredictions() method?
我正在使用这个方法:
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);
我正在使用这个方法:
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);