Based on my research of the space we are in Backendless is the only mBaaS platform that lets you use SQL queries when searching for data. The geolocation data managed by Backendless is not an exception. A geopoint may include metadata, which is an arbitrary collection of key/value pairs. Geopoints may be searched for using SQL based queries. A query must be the “where” part of a traditional SQL statement. It can reference the metadata properties as if they are table columns.
The example below uses the sample data which can be installed into any Backendless backend. The data is a collection of geo points representing cities around the world. Each geo point contains metadata with the name of the city. The sample below runs the following SQL query:
1 |
city in ('AUSTIN', 'DALLAS') |
The query searches for all database where the metadata property name is “city” and the value may be either ‘AUSTIN’ or ‘DALLAS’:
Asynchronous sample (Android and Plain Java):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
BackendlessGeoQuery geoQuery = new BackendlessGeoQuery(); geoQuery.addCategory( "geoservice_sample" ); geoQuery.setIncludeMeta( true ); geoQuery.setWhereClause( "city in ('AUSTIN', 'DALLAS')" ); Backendless.Geo.getPoints( geoQuery, new AsyncCallback<BackendlessCollection<GeoPoint>>() { @Override public void handleResponse( BackendlessCollection<GeoPoint> geoPointCollection ) { Iterator<GeoPoint> iterator = geoPointCollection.getCurrentPage().iterator(); while( iterator.hasNext() ) { GeoPoint geoPoint = iterator.next(); System.out.println( "GeoPoint - " + geoPoint ); } } @Override public void handleFault( BackendlessFault backendlessFault ) { System.out.println( "Server reported an error - " + backendlessFault.getMessage() ); } } ); |
Synchronous sample (Plain Java only):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
BackendlessGeoQuery geoQuery = new BackendlessGeoQuery(); geoQuery.addCategory( "geoservice_sample" ); geoQuery.setIncludeMeta( true ); geoQuery.setWhereClause( "city in ('AUSTIN', 'DALLAS')" ); BackendlessCollection<GeoPoint> geoPointCollection = Backendless.Geo.getPoints( geoQuery ); Iterator<GeoPoint> iterator = geoPointCollection.getCurrentPage().iterator(); while( iterator.hasNext() ) { GeoPoint geoPoint = iterator.next(); System.out.println( "GeoPoint - " + geoPoint ); } |
The program produces the following output:
1 2 3 |
GeoPoint - GeoPoint{objectId='55DEE179-A7EE-9491-FF5A-6644F8E10200', latitude=43.66663, longitude=-92.97464, categories=[geoservice_sample], metadata={city=AUSTIN}, distance=null} GeoPoint - GeoPoint{objectId='D60EFC78-673D-0DA8-FFD7-53C8D8BF8D00', latitude=32.78306, longitude=-96.80667, categories=[geoservice_sample], metadata={city=DALLAS}, distance=null} GeoPoint - GeoPoint{objectId='C594A668-B9A2-4D24-FF5A-D4F700DECB00', latitude=30.26715, longitude=-97.74306, categories=[geoservice_sample], metadata={city=AUSTIN}, distance=null} |
Enjoy!