2

我在 osmdroid (3.05) 中使用 fromPixels() 函数,如下所示:

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 所以看起来纬度距离很远(转换为十进制
度是好的 - 我只是乘以 1E-6)
我使用的是功能不正确?
从我读到的似乎我的用法很好,我还读到该
功能曾经有问题,但现在应该修复

提前致谢!
暗里

4

1 回答 1

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

@Override
public void computeScroll() {
    if (mScroller.computeScrollOffset()) {
        if (mScroller.isFinished()) {
            // This will facilitate snapping-to any Snappable points.
            setZoomLevel(mZoomLevel);
        } else {
            /* correction for double tap */
            int targetZoomLevel = getZoomLevel();
            if (targetZoomLevel == mZoomLevel)
                scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
        }
        postInvalidate(); // Keep on drawing until the animation has
        // finished.
    }
}
于 2011-11-18T20:15:23.080 回答