gpt4 book ai didi

android - 如何将 MapView 从像素缩放到米

转载 作者:行者123 更新时间:2023-11-29 00:34:10 25 4
gpt4 key购买 nike

我正在制作一个使用 Google Maps API 的 Android 应用程序,我想将 MapView 缩放到 X_pixels:X_meters。

例如,我屏幕上 MapView 的 5 个像素,现实中的 20 米。

这可能吗?

谢谢

最佳答案

使用以下代码:

    int nPixles = 5; //number of pixels
GeoPoint g0 = mapview.getProjection().fromPixels(0, mapview.getHeight()/2);
GeoPoint g1 = mapview.getProjection().fromPixels(nPixles, mapview.getHeight()/2);
float[] results = new float[1];
Location.distanceBetween(g0.getLatitudeE6()/1E6, g0.getLongitudeE6()/1E6, g1.getLatitudeE6(), g1.getLongitudeE6()/1E6, results);
float distanceInMeters = results[0];

这会计算屏幕中心纬度级别的距离(以米为单位)。因为地球是球体,所以屏幕底部到顶部的距离不同。这主要是在低缩放级别时注意到的。

问候。

关于android - 如何将 MapView 从像素缩放到米,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13635551/

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