2011-09-05 78 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