2011-09-05 76 views
2

我使用的fromPixels()在osmdroid(3.05)函数,如下所示:问题从像素转换成纬度/经度

public boolean onScroll(ScrollEvent e) { 

    //get the scroll's destination 
    GeoPoint g = (GeoPoint) e.getSource().getProjection().fromPixels(e.getX(), e.getY()); 
    Toast.makeText(e.getSource().getContext(), "in e6: " + 
    g.getLongitudeE6() + " " + g.getLatitudeE6() + " in deg's" + 
    convertToDecimalDegrees(g.getLongitudeE6()) 
    + " " + convertToDecimalDegrees(g.getLatitudeE6()), Toast.LENGTH_LONG).show();} 

我滚动地图邻近-0.0029109 51.9933734的地方,但在烤面包我得到:
-0.9613029999999999 76.60554499999999因此它似乎LAT是方式关闭(转换为十进制
度是好的 - 我只是乘以1E-6)
现在用的函数不正确吗?
从我读它看起来像我的使用什么是好的,我也读过,有曾经是一个问题
那个函数但是它现在应当事先固定

谢谢!
欧米

+0

这线程双击错误的修正是这一个非常类似:http://stackoverflow.com/questions/7898313/limit-scrolling-on-离线地图在Android – rahstame

回答

0

我知道这个线程是有点老了,但这个问题的答案可以在http://code.google.com/p/osmdroid/issues/detail?id=209 被发现的一点是要设置地图的最大范围和限制滚动到那种程度。 下面是上面提到的问题的总结(添加的代码下面MapView.java)

protected Rect mScrollableAreaLimit = null; 

public void setScrollableAreaLimit(BoundingBoxE6 boundingBox) { 
    final int worldSize_2 = TileSystem.MapSize(MapViewConstants.MAXIMUM_ZOOMLEVEL)/2; 
    // Clear scrollable area limit if null passed. 
    if (boundingBox == null) { 
     mScrollableAreaLimit = null; 
     return; 
    } 

    // Get NW/upper-left 
    final Point upperLeft = TileSystem.LatLongToPixelXY(boundingBox.getLatNorthE6()/1E6, 
      boundingBox.getLonWestE6()/1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null); 
    upperLeft.offset(-worldSize_2, -worldSize_2); 

    // Get SE/lower-right 
    final Point lowerRight = TileSystem.LatLongToPixelXY(boundingBox.getLatSouthE6()/1E6, 
      boundingBox.getLonEastE6()/1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null); 
    lowerRight.offset(-worldSize_2, -worldSize_2); 
    mScrollableAreaLimit = new Rect(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y); 
} 

现在你可以调用setScrollableAreaLimit方法创建地图视图的时候,也可以用BoundingBoxE6参数扩大构造。

希望这会有所帮助。

除了这是需要http://code.google.com/p/osmdroid/issues/detail?id=209#c23

+0

只看到了这一点,感谢很多!我会试一试。 – omri