2017-04-18 121 views
2
Point da = map1().getMapPosition(48.922499263758255, 16.875); 
System.out.println(da); 

有人可以幫助我嗎?我想通過使用這個getMapPosition將座標轉換爲點,但無論我做什麼,它都會給我一個null值。爲什麼會發生?getMapPostition返回空值

謝謝。

回答

1

對相關JMapViewer信息源的快速檢查顯示,您致電getMapPosition()時會調用附近的超載,其中checkOutside設置爲true。如果與座標對應的Point位於可見圖之外,則結果爲null

if (checkOutside && (p.x < 0 || p.y < 0 || p.x > getWidth() || p.y > getHeight())) { 
    return null; 
} 

相反,使用,可以讓你設置checkOutsidefalse明確的實現方式之一。例如,

Point da = map1().getMapPosition(48.9225, 16.875, false); 

Coordinate coord = new Coordinate(48.9225, 16.875); 
Point da = map1().getMapPosition(coord, false); 
+1

非常感謝主席先生的回覆,我想通了,我說錯了,我只需要創建一個變量座標座標然後添加假 點達= map1()。getMapPosition(coord,false); 那麼它給了我現在正確的點值tnx很多:) – Renrenren