LatLngBounds 构造函数的定义如下:
LatLngBounds (LatLng southwest, LatLng northeast)
例如,它需要两个LatLng值,一个用于边界的西南位置,另一个用于边界的东北位置,矩形的另外两个点可以轻松计算。
If yes, then what are the values of LatLngBounds for United States?
如果我没猜错的话,美国的西南角经纬度值应该是32.6393,-117.004304,东北角经纬度值应该是44.901184,-67.32254。
Which source did you use to get LatLngBounds for a country?
我通常使用http://www.findlatitudeandlongitude.com/来检查那些需要在所需位置放置标记的LatLng值。
LatLngBounds is a rectange - so it can include other countries in the result as well. What about that?
是的,您说得对,上述范围将是纯矩形,使用这些范围无法将结果限制在仅限美国的范围内。
这是因为矩形 [bounds] 将使用我们提供给构造函数的两个 Latlng 点 [SE 和 NW] 进行计算,另外两个点将被轻而易举地计算出来。
Is there a better way to do it?
是的,您可以使用 Google Places Web Service API。下面的教程解释了如何使用该API:
http://codetheory.in/google-place-api-autocomplete-service-in-android-application/。
您可以使用地址类型和地址组件以您所需的方式使用此API来限制结果:
https://developers.google.com/maps/documentation/geocoding/intro#Types。
使用上述链接中提到的类型,您可以按国家、地区和其他类型进行限制。
希望对您有所帮助!
P.S:如果有人知道如何在Play Services API中使用Bounds将其限制到特定国家,请回答,这会非常棒!