HelloWorld
HelloWorld

Reputation: 2355

How to correctly use BoundingBox getNE and getSW in Codename One

My app features a MapContainer on which I want to draw a marker for each report in the database. As there could be thousands of reports simultaneously in the database and as many users of my app, I want to always add markers for the reports that can be displayed on the map area actually displayed.

That's why I only ask the database for records that lay within South West and North East bounds. On simulator it works great, the reports are plotted where they should on the map.

I get the NE and SW bounds with the following commands :

MapContainer googleMap = new MapContainer("MyGoogleMapsKeyForJavaScript");
Coord NE = googleMap.getBoundingBox().getNorthEast();
Coord SW = googleMap.getBoundingBox().getSouthWest();

However on the actual device (Android 4.4) the records are not retrieved because the device asks for reports within bounds that are ouside France (where the app is intended to be used).

So for example, the device shows a map centered on France, where I can also see Spain, Portugal, Italy, Belgien, a part of Germany. To sum up, the map shows western Europe (see screen capture below where the MapContainer is circled in red).

enter image description here

Now if I display the NE and SW coordinates, the NE is somewhere in Libya and the SW somewhere in Guinea (see below where the NE and SW bounds have been manually added to the map). So the bounding box is in Afrika, and does not embrace the location I see on the map.

enter image description here

Consequently as the bounding box has nothing to do with the map displayed, the database cannot retrieve records in Afrika when all records are in France.

Moreover the more I zoom in the more the map goes northern. I don't display the zoom but actually when I zoom to a very high level (18+ I guess) then the report appear on the map. But I have to zoom exactly where I know the report is, whereas on the simulator, the reports are plotted everytime they lay in the bounding box (which seems correct although I cannot display the value because of the other issue I encounter).

Did I make a mistake in my understanding of how to use NE / SW bounds, why is it working in the simulator but not on the real device ? Or is it just a bug on this specific device and it won't happen on more modern devices ?

Any lights shed on this issue would help a lot,

Upvotes: 0

Views: 120

Answers (1)

steve hannah
steve hannah

Reputation: 4716

Getting the bounding box before the MapContainer has been added to the UI will yield undefined results. The bounding box is the bounds of the Map that are visible in the UI. Until the map has been added to the UI, we don't know what the bounds will be...

Upvotes: 1

Related Questions