Skip to content

Search in Rectangular Area

This API runs a search within a rectangular area of the map. The area is defined with the coordinates of the North West and South East corners of the map rectangle.


Future<List<GeoPoint>> Backendless.geo.getPoints({BackendlessGeoQuery query});


Argument                Description
query a query object encapsulating the search parameters. See the Running Search Queries section below for details.

Return Value

A collection of GeoPoint objects matching the search query. Each GeoPoint instance contains the following properties:

Argument                Description
objectId ID assigned to geo point by Backendless when it is saved in the backend geo location storage.
latitude latitude of the geo point.
longitude longitude of the geo point.
categories an array of geo categories the point belong to.
metadata metadata associated with the geo point. Accepted values for this parameter are: String, Number (integer and double), and property names of the related objects stored in the database. Date values must be represented as number in the Unix timestamp format (number of milliseconds since January 1, 1970 at UTC). Learn more about using date in search queries for category, radius, or rectangular area search.
distance distance between the center point referenced in the search query and the geo point. The distance is always in units specified in the search query.

All geo points in the entire search result are indexed. The index of the first geo point is 0. The offset parameter in the query object and in some method of BackendlessCollection specifies the index from which to load the next page of geo points. For example, suppose the entire search result is 200 points (the totalObjects value returned in the collection is 200). If the initial pageSize is 20, then only 20 geo points are returned in the first response. To get the second page of geo points, they should be loaded from offset 20, third from 40 and so on. The formula for calculating the offset is:
 [value of offset in the current response] + [size of current page ].

Running Search Queries

The geo query object includes multiple parameters, however, only the coordinates defining the rectangular area are required.  A search query must be performed within at least one category. If no category names are provided, the search is performed in the Default category.

Search in a rectangle in categories

Rectangle-based search establishes a geographic area by setting the coordinates of the North West and South East corners of the area. Backendless searches for geo points in the specified area and includes them into the search result:

BackendlessGeoQuery geoQuery = BackendlessGeoQuery()
  ..categories = ["Restaurants"]
  ..searchRectangle = [32.78, -96.8, 25.79, -80.22];

Backendless.geo.getPoints(query: geoQuery).then((geoPoints) {
  print("Result: $geoPoints");

Search in categories in a rectangular area and metadata

This is the same as above, with the difference that the search result includes only geo points with the matching metadata:

BackendlessGeoQuery geoQuery = BackendlessGeoQuery()
  ..categories = ["Restaurants"]
  ..searchRectangle = [32.78, -96.8, 25.79, -80.22]
  ..metadata = {
    "Cuisine": "French",
    "Athmosphere": "Romantic",

Backendless.geo.getPoints(query: geoQuery).then((geoPoints) {
  print("Result: $geoPoints");

Using dates in where clause

The search query used to retrieve geo points may reference date values. These values must be stored as a number of milliseconds since January 1st, 1970 at UTC. The example below demonstrates the usage of a date/time timestamp in a search query:

void searchByDateInRectangularArea() {
  // date
  DateTime opened = DateTime.parse("2015-01-17 07:00:00");
  DateTime closed = DateTime.parse("2015-01-17 23:00:00");
  DateTime now = DateTime.parse("2015-01-17 15:20:00");

  // create geo point
  GeoPoint geoPoint = GeoPoint.fromLatLng(21.306944, -157.858333)
    ..categories = ["Coffee"]
    ..metadata = {
      "Name": "Starbucks",
      "opened": opened.millisecondsSinceEpoch,
      "closed": closed.millisecondsSinceEpoch,

  Backendless.geo.savePoint(geoPoint).then((savedGeoPoint) {
    // search
    GeoPoint nortWestCorner = GeoPoint.fromLatLng(21.306944 + 0.5, -157.858333 - 0.5);
    GeoPoint southEastCorner = GeoPoint.fromLatLng(21.306944 - 0.5, -157.858333 + 0.5);
    BackendlessGeoQuery geoQuery = BackendlessGeoQuery.rectangle(nortWestCorner, southEastCorner)
      ..categories = ["Coffee"]
      ..whereClause = "opened < ${now.millisecondsSinceEpoch} AND closed > ${now.millisecondsSinceEpoch}"
      ..includeMeta = true;

      Backendless.geo.getPoints(query: geoQuery).then((points) {
        print("searchByDateInRectangularArea GETPOINTS: $points");

Requesting meta in response

Geo points returned in the search results do not include their metadata properties by default. The search query object includes a property which can be used to request the metadata to be included. This property can be used with any search options described above. The syntax for requesting metadata in response is described in the Search in Category section.