gpt4 book ai didi

android - 平板电脑上的 Mapview : How can I center the map with an offset?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:05:10 24 4
gpt4 key购买 nike

提示:这是一个similar post使用 HTML。

在我的应用程序的当前平板电脑实现中,我有一个全屏 MapView,其中一些信息显示在左侧面板的 RelativeLayout 中,如下所示:

(我的布局很琐碎,为了便于阅读,我想没有必要发布它)

enter image description here

当我想将 map 置于特定点的中心时,问题就来了...如果我使用此代码:

mapController.setCenter(point);

我当然会得到屏幕中心的点,而不是空白区域的中心。

我真的不知道从哪里开始可以将左侧面板的偏移量转换为 map 坐标...

非常感谢任何帮助或建议

最佳答案

您可以通过从 top-leftbottom-right 角获取 map 坐标并将其除以屏幕尺寸来实现您的目标,以获得每个像素的值.

然后你只需要乘以偏移量并将它添加到原来的中心。

示例代码:

private void centerMap(GeoPoint center, int offX, int offY){
GeoPoint tl = mapView.getProjection().fromPixels(0, 0);
GeoPoint br = mapView.getProjection().fromPixels(mapView.getWidth(), mapView.getHeight());

int newLon = offX * (br.getLongitudeE6() - tl.getLongitudeE6()) / mapView.getWidth() + center.getLongitudeE6();
int newLat = offY * (br.getLatitudeE6() - tl.getLatitudeE6()) / mapView.getHeight() + center.getLatitudeE6();

mapController.setCenter(new GeoPoint(newLat, newLon));

}

要使用,您可以使用原始中心和要应用的两个偏移量(x 和 Y)调用上述方法。

注意: 如所写,上面的代码将 map 向左移动为正偏移值,向右移动为负偏移值。从您问题的屏幕上,您将需要使用负偏移,将 map 向左移动,并为 Y 设置零偏移。

问候

关于android - 平板电脑上的 Mapview : How can I center the map with an offset?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13320386/

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