平板电脑上的Mapview:如何将地图与偏移量对齐? [英] Mapview on tablet: How can I center the map with an offset?
问题描述
(我的布局非常简单,我想不需要为了便于阅读而发布它)
问题出现在我想要将地图放在特定点上时...如果我使用以下代码:
mapController.setCenter(点);
我当然会在屏幕的中心获得该点,而不是在空的中心地区。
我真的不知道在哪里可以开始将左侧面板的偏移量转换为地图坐标...
非常感谢您的帮助或建议
您可以通过从左上角
和右下角
角,并将其除以屏幕尺寸,以获得每像素的值。 p>
然后,您只需乘以偏移量并将其添加到原始中心即可。
示例代码: p>
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));
$ b $ / code>
要使用,请使用原始中心调用上述方法和两个偏移量(x和Y)来应用。
问候 Hint: Here is a similar post with HTML. In the current tablet implementation of my app, I have a fullscreen MapView with some informations displayed in a RelativeLayout on a left panel, like this: (My layout is quite trivial, and I guess there is no need to post it for readability) The problem comes when I want to center the map on a specific point... If I use this code: I will of course get the point in the center of the screen and not in the center of the empty area. I have really no idea where I could start to turn the offset of the left panel into map coordinates... Thanks a lot for any help or suggestion You can achive your objective by getting the map coordinates from Then you just need to multiply by the offset and add it to the original center. Example code: To use, you call the above method with your original center and both offsets (x and Y) to apply. Regards 这篇关于平板电脑上的Mapview:如何将地图与偏移量对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!注意:正偏移值,右负偏移值。从问题的屏幕中,您需要使用负偏移量,左移移动地图和Y的零偏移量。
mapController.setCenter(point);
top-left
and bottom-right
corners and divide it by the screen size, to get the value per pixel.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));
}
Note:
as written, the code above move map left for positive offset values, and right for negative offset values. From the screen in your question you will need to use negative offset, to move map left, and a zero offset for Y.