Question

I am using the fromPixels() function in osmdroid (3.05) like so:

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();}  

I am scrolling the map somewhere near -0.0029109 51.9933734 but in the toast i get:
-0.9613029999999999 76.60554499999999 so it seems like the lat is way off (the convert to decimal
degrees is Ok - i just multiply by 1E-6)
Am i using the function incorrectly?
From what i read it seems like my usage is fine, also i read that there used to be a problem with
that function but that it should be fixed now

Thanks in advance!
Omri

Was it helpful?

Solution

I know this thread is a little old but the answer to this question can be found on http://code.google.com/p/osmdroid/issues/detail?id=209 To point is to set max extent of map and restrict scrolling to that extent. Below is the summary of issue mentioned above (Add the code below to 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);
}

Now you can call the setScrollableAreaLimit method when map view is created or you can expand constructor with BoundingBoxE6 parameter.

Hope this helps.

In addition to this a correction for double tap bug is needed 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.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top