【问题标题】:How to zoom Google Map accordingly on a returned result from Places API?如何根据 Places API 返回的结果相应地缩放 Google 地图?
【发布时间】:2019-12-22 12:22:12
【问题描述】:

我目前正在尝试实现流畅的缩放动画,谷歌地图有,例如,如果用户搜索一个城市,地图会缩放到足够多,所以他可以看到整个城市,如果他搜索一个国家变焦要大得多。我目前已经达到了获取 Place 对象及其 LatLng 数据的地步,但还没有找到针对给定搜索正确缩放的方法。

据我所知,应该通过向 RectangularBounds 对象提供西南和东北点并将其设置到地图来完成,但还没有找到使用 Android API 完成此操作的方法

【问题讨论】:

  • 我相信 Places API 应该返回每个项目的视图端口。

标签: android google-maps google-places-api


【解决方案1】:

您应该使用Places SDK for Android 中的Place.getViewport() 方法来获取适合显示大小的视口(@98​​7654323@),然后在animateCamera()moveCamera() 方法中使用它。类似的东西:

// get place from places API response
Place place = places.get(0);

int padding = 0; // padding  in pixels
LatLngBounds = bounds place.getViewport();
if (bounds != null) {
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    googleMap.animateCamera(cameraUpdate);
}

【讨论】:

  • 感谢您的意见,这正是我所需要的!
猜你喜欢
  • 1970-01-01
  • 2015-09-18
  • 2017-07-14
  • 1970-01-01
  • 1970-01-01
  • 2019-02-04
  • 1970-01-01
  • 1970-01-01
  • 2014-01-14
相关资源
最近更新 更多