@
eronquillo
I don't think you'll find a specific example that'll do as you require.
You say an MySQL database so presumably you're storing the coordinates online and not locally on the device?
Take a look at this Google search
https://www.google.co.uk/search?q=mysql spatial extensions&ie=UTF-8&oe=UTF-8.
You'd make things easier to do if you use MySQL spatial extensions to store the coordinate data.
It'll take a bit more time to set up table columns using a spatial data type instead of a float or double data type but once set up you'll be able to make much more efficient queries.
Next, if each time the map is panned or zoomed you query your database for coordinates within the map bounds then you'll probably find you're making too many queries - if the user slowly pans the map bit by bit for example you don't want to query the database repeatedly.
I'm not sure what best to suggest here, ideally you want to have the database locally on the device so you don't have to wait for network requests to complete.
Have you seen the
Spatialite library?
Spatialite is basically SQLite with spatial extensions.
A local (device based) spatialite database would enable you to make queries much faster and more efficiently than a remote MySQL database.
I think what i'd try to do is:
- Fetch all coordinates from the database in a single query.
- Create a b4a Type with properties to contain the coordinate data, use a GeoPoint type for the coordinate property.
- Iterate through the database query result creating a List of these b4a Type objects - an object for each row in the results.
So you now have a List of objects, each object has a GeoPoint type property.
When you want to update the Markers, get the map bounds as a BoundingBox and iterate through the List of objects:
- If the object's GeoPoint is within the BoundingBox and the object hasn't yet been added to the map as a Marker then create and add a Marker to the map.
If a Marker has already been created for the object and added to the map then do nothing.
- If the object's GeoPoint is not within the BoundingBox and the object has a corresponding Marker on the map then remove the Marker.
If the object has no corresponding Marker then do nothing.
Martin.