gpt4 book ai didi

android - MapFragment中的函数getMapCenter/从MapFragment中获取MapView

转载 作者:行者123 更新时间:2023-11-29 21:50:12 28 4
gpt4 key购买 nike

我的 Android 应用程序中有一个 MapFragment,现在我想知道 map 上实际显示的最小和最大纬度/经度。

我找到了这个解决方案:

If you want to find out the longitude latitude of the corners of the MapView you could use:

Point mapCenter = mapView.getMapCenter();
int latitudeSpan = mapView.getLatitudeSpan() / 2;
int longitudeSpan = mapView.getLongitudeSpan() / 2;
int topLeftLat = mapCenter.getLatitudeE6() + (latitudeSpan);
int topLeftLon = mapCenter.getLongitudeE6() - (longitudeSpan);
int bottomLeftLat = mapCenter.getLatitudeE6() - (latitudeSpan);
int bottomLeftLon = mapCenter.getLongitudeE6() + (longitudeSpan);

我现在的问题是我没有 MapView,我只有一个 GoogleMap (com.google.android.gms.maps.GoogleMap) 和一个 MapFragment (com.google.android.gms.maps.MapFragment)。

我需要最小/最大坐标来执行数据库查询以选择 POI-DB-Entry。

最佳答案

您可以使用 getVisibleRegion 从您的 GoogleMap 获取它来自 Projection

假设您将 GoogleMap 命名为 map,您这样做

VisibleRegion bounds = map.getProjection().getVisibleRegion();

VisibleRegion 不一定是矩形,但会为您提供边界,请参阅 docs了解更多信息。

关于android - MapFragment中的函数getMapCenter/从MapFragment中获取MapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14634735/

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