2012-08-06 63 views
4

我试图将屏幕坐标转换为android mapview中的地理坐标。我需要在屏幕中心显示一个标记(mapview填充在窗口中)。所以我尝试使用display metrics getWidth()和getHeight()方法获取中心坐标,并使用mapView.getProjection()。fromPixels(height/2,width/2)将其转换为geoppo点。但它似乎给了错误的结果。我该怎么办?如何将屏幕坐标转换为android中的位置点

回答

5

你传递的高度和宽度的说法是错误的改变

mapView.getProjection().fromPixels(width/2,height/2);

试试这个代码

Projection proj = mapview.getProjection(); 
GeoPoint proj.fromPixels(int x, int y) ; 

在这里,你必须通过X,Y坐标,它会转换到GeoPoint,您也可以从GeoPoint保留这个像素也从这个对象的像素

Point p = new Point(); 
proj.toPixels(GeoPoint in, android.graphics.Point out) 

检查此链接了解更多信息

https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/Projection

0

你是否考虑到notificationBar大小?也许还有appBar

你想知道的是宽度和高度的MapView,然后得到投影:)

相关问题