问题描述
我的代号一个应用程序具有MapContainer。我需要在其上显示驻留在服务器上的兴趣点(POI)。服务器上可能有数百个(将来可能成千上万个)此类POI。这就是为什么我只想从服务器下载可以在地图上显示的POI。因此,我需要获取地图边界才能将其传递到服务器。
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.
我阅读了和其他,并且该键似乎可以获取地图Projection和地图边界框。但是,getProjection()方法或getBoundingBox()似乎没有公开。
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.
一种解决方案是将 getCameraLocation()
的坐标与地图中心和 getZoom()
来推断这些边界。但是它可能因设备而异(请参见所示区域可以更大)。
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).
如何在Codename one中获得地图边界?
How can get the map boundaries in Codename one ?
任何帮助表示赞赏,
干杯,
推荐答案
问题出在getCoordAtPosition()的javadocs中。这将得到纠正。
The problem is in the javadocs for getCoordAtPosition(). This will be corrected. getCoordAtPosition() expects absolute coordinates, not relative.
例如
Coord NE = currentMap.getCoordAtPosition(currentMap.getWidth(), 0);
Coord SW = currentMap.getCoordAtPosition(0, currentMap.getHeight());
应该
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.
编辑2017年3月21日:事实证明,某些平台期望相对坐标,而另一些平台则期望绝对坐标。我必须对其进行标准化,并且我选择在所有平台上使用相对坐标来与Javadocs保持一致。因此,您的第一次尝试是:
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.
我还添加了另一种方法: getBoundingBox()
,它将为您提供边界框,而无需担心相对/绝对坐标。
I have also added another method : getBoundingBox()
that will get the bounding box for you without worrying about relative/absolute coordinates.
这篇关于如何在代号一中获取我的MapContainer边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!