How to get my MapContainer bounding box in Codename One

南笙酒味 提交于 2019-12-09 21:36:34

问题


My Codename One app features a MapContainer. I need to show points of interest (POIs) on it which coordinates reside on the server. There can be hundreds (maybe thousands in the future) of such POIs on the server. That's why I would like to only download from the server the POIs that can be shown on the map. Consequently I need to get the map boundaries to pass them to the server.

I read this for Android and this other SO question for iOS and the key seems to get the map Projection and the map bounding box. However the getProjection() method or the getBoundingBox() seem not to be exposed.

A solution could be to mix the coordinates from getCameraLocation() which is the map center and getZoom() to infer those boundaries. But it may vary depending on the device (see the shown area can be larger).

How can get the map boundaries in Codename one ?

Any help appreciated,

Cheers,


回答1:


The problem is in the javadocs for getCoordAtPosition(). This will be corrected. getCoordAtPosition() expects absolute coordinates, not relative.

E.g

Coord NE = currentMap.getCoordAtPosition(currentMap.getWidth(), 0); 
Coord SW = currentMap.getCoordAtPosition(0, currentMap.getHeight());

Should be

Coord NE = currentMap.getCoordAtPosition(currentMap.getAbsoluteX() + currentMap.getWidth(), currentMap.getAbsoluteY()); 
Coord SW = currentMap.getCoordAtPosition(currentMap.getAbsoluteX(), currentMap.getAbsoluteY() + currentMap.getHeight());

I tried this out on the coordinates that you provided and it returns valid results.

EDIT March 21, 2017 : It turns out that some of the platforms expected relative coordinates, and others expected absolute coordinates. I have had to standardize it, and I have chosen to use relative coordinates across all platforms to be consistent with the Javadocs. So your first attempt:

Coord NE = currentMap.getCoordAtPosition(currentMap.getWidth(), 0); 
Coord SW = currentMap.getCoordAtPosition(0, currentMap.getHeight());

Will now work in the latest version of the library.

I have also added another method : getBoundingBox() that will get the bounding box for you without worrying about relative/absolute coordinates.




回答2:


This is probably something that can be exposed easily by forking the project and providing a pull request. We're currently working on updating the map component so this is a good time to make changes and add features.



来源:https://stackoverflow.com/questions/42096174/how-to-get-my-mapcontainer-bounding-box-in-codename-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!