gpt4 book ai didi

android - 如何为 Google Places API get AutocompletePrediction() 方法提供合理的默认范围?

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:18 37 4
gpt4 key购买 nike

我正在使用这个方法:

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

关于android - 如何为 Google Places API get AutocompletePrediction() 方法提供合理的默认范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32455391/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com