gpt4 book ai didi

android - 将屏幕尺寸(像素)转换为纬度和经度

转载 作者:行者123 更新时间:2023-11-29 22:04:42 25 4
gpt4 key购买 nike

好的,所以我正在尝试编写一个代码,根据当前可查看区域返回 map 所有 4 个角位置的值。例如,用户通过他的设备访问谷歌地图,他关注一个特定区域并点击一个按钮并返回所有四个角的位置(纬度和经度)。

为此,我有中心坐标,现在我想要的是当前可视区域的跨度,并获得左上角和右下角坐标。为此,我使用了

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x; // returns 480
int height = size.y; // returns 800

现在我想将它们转换为纬度和经度值,以便我可以使用简单的数学运算,例如:

topLeftLat= centerLat + lat/2;
topLeftLon= centerLon - lng/2;
bottomRightLat= centerLat - lat/2;
bottomRightLon = CenterLon + lng/2;

这会给我角坐标。lat 和 lng 是经度和纬度值转换后的屏幕分辨率。

最佳答案

这在谷歌上搜索了 5 分钟,所以我不知道我为什么要给你这个...学习研究是成为开发人员最重要的部分。

GeoPoint mapCenter = myMap.getMapCenter();

float centerLatitude = (float)(mapCenter.getLatitudeE6())/1000000;
float centerLongitude = (float)(mapCenter.getLongitudeE6())/1000000;

float latitudeSpan = (float)(myMap.getLatitudeSpan())/1000000;
float longitudeSpan = (float)(myMap.getLongitudeSpan()/1000000);

GeoPoint mapTopLeft = myMap.getProjection().fromPixels(0, 0);
float topLatitude = (float)(mapTopLeft.getLatitudeE6())/1000000;
float leftLongitude = (float)(mapTopLeft.getLongitudeE6())/1000000;

GeoPoint mapBottomRight
= myMap.getProjection().fromPixels(myMap.getWidth(), myMap.getHeight());
float bottomLatitude = (float)(mapBottomRight.getLatitudeE6())/1000000;
float rightLongitude = (float)(mapBottomRight.getLongitudeE6())/1000000;

String info =
"Center: " + centerLatitude + "/" + centerLongitude + "\n"
+ "Top Left: " + topLatitude + "/" + leftLongitude + "\n"
+ "Bottom Right: " + bottomLatitude + "/" + rightLongitude + "\n"
+ "latitudeSpan: " + latitudeSpan + "\n"
+ "longitudeSpan: " + longitudeSpan + "\n";

Toast.makeText(AndroidMapActivity.this,
info,
Toast.LENGTH_LONG).show();
}};

完整教程可在 Android-er: Get the the coordinates (Latitude and Longitude) currently displayed on MapView 获得

关于android - 将屏幕尺寸(像素)转换为纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11019965/

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