- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
提示:这是一个similar post使用 HTML。
在我的应用程序的当前平板电脑实现中,我有一个全屏 MapView,其中一些信息显示在左侧面板的 RelativeLayout 中,如下所示:
(我的布局很琐碎,为了便于阅读,我想没有必要发布它)
当我想将 map 置于特定点的中心时,问题就来了...如果我使用此代码:
mapController.setCenter(point);
我当然会得到屏幕中心的点,而不是空白区域的中心。
我真的不知道从哪里开始可以将左侧面板的偏移量转换为 map 坐标...
非常感谢任何帮助或建议
最佳答案
您可以通过从 top-left
和 bottom-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/
我的应用程序中有两个 Activity 。第一个 Activity 启动模式是 singleInstance,第二个 Activity 启动模式是 singleTask。我正在使用这些启动模式,因为我
据热心网友投稿,小米小爱触屏音箱Pro 8外观曝光,可以看到触控屏幕尺寸比较大,像是在音箱上“长”了一个平板。 从曝光的信息来看,小米小爱触屏音箱Pro 8具有白色的配色设计,下方有一个长
我有一张 table ,看起来像, VisitorId date deviceType 1 2018-12-11 mobile 2
今天下午,小米官方公布了小爱触屏音箱Pro 8,可以看到触控屏幕尺寸比较大,音箱上“长”了一个平板。据悉,小米小爱触屏音箱Pro 8具有白色的配色设计,下方有一个长条状的扬声器,上方带有一个尺寸比较
有没有办法检测是否使用手持浏览器(iOS/Android 手机/平板电脑)? 我尝试这样做的目的是让手持设备上的浏览器中的元素宽度减半,但这并没有什么不同。 width: 600px; @media
目前,Google Analytics for web 公开了一个设备类别字段,其离散值为mobile、tablet 和desktop。该界面还允许您更深入地了解它的具体设备。我想 Google 有某
我是一名优秀的程序员,十分优秀!