Skip to content

Search in Radius

This API supports multiple types of geo searches:

  • Search for geo points located within specified distance (radius) from a given point.
  • Search in radius based on metadata.

Method

GET

URL

https://api.backendless.com/<application-id>/<REST-api-key>/geo/points?  
lat=<latitude>&  
lon=<longitude>&  
categories=<categories>&  
r=<radius>&  
units=<units>&  
metadata=<metadata>&  
pagesize=<pagesize>&  
includemetadata=<includemetadata>&  
offset=<offset> 

where:

Argument                Description
<application id> ID of the application which can be obtained from the Manage > App Settings screen of the Backendless Console
<REST-api-key> REST API key of your application. You can get the value from the Manage > App Settings section of the Backendless Console.
<latitude> latitude of the point in the center of the search.
<longitude> longitude of the point in the center of the search.
<categories> list of categories separated by comma where to run the search. If the parameter is not present in the request, the search is ran in the "Default" category.
<radius> distance from the center point within which to run the search.
<units> unit of measure applied to the radius value. Supported unit values are: METERS, KILOMETERS, MILES, YARDS, FEET
<metadata> metadata which must match in order for a point to be selected for the search result. Must be expressed in as a URL encoded JSON object. For example, { "foo":"bar" } will be URL encoded as:  %20%7B%20%22foo%22%3A%22bar%22%20%7D. Found geo points must match the specified metadata key/value pairs entirely. 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.
<pagesize> number of geo points to be returned in the response.
<includemetadata> Boolean value indicating whether geo point metadata should be included in the response. Supported values are true or false.
<offset> sequential (zero-based) index from where to run the search. For example, suppose the first search query returned 50 geo points (pageSize is set to 50). A subsequent search should set the offset value to 50 in order to get the next page of search results.

Request headers

user-token: optional value obtained as a result of the login operation.

where:

Argument                Description
user-token Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-token is set in the request, the currently logged in user will be assigned to the ownerId property of the user object which is being saved.  Additionally, the operation will be executed with the security policy associated currently logged in user. This means all permissions associated with the user and the roles assigned to the user will be enforced by Backendless.

Request Body

none

Response Body

A JSON array of geopoint objects. Each object contains the following properties:

Argument                Description
objectId an ID assigned to a geo point by Backendless.
latitude geo point's latitude coordinate
longitude geo point's longitude coordinate
categories an array of categories the geo point belongs to
metadata a JSON object of key/value pairs describing geo point's metadata properties

Since the search query may produce a large number of geo points, not all of them are returned at once. Instead, all found geo points are divided into 'pages'. The size of each page is determined by the pageSize parameter in the query. The first response returns the first page. Subsequent search requests with the modified offset will return additional pages of data.

Calculating offset

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 specifies the index from which to load the next page of geo points. For example, suppose the entire search result is 200 points. 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 offset is:

[value of offset in the current response] + [size of current page ].

If an error occurs, the response is formatted as described in the Error Handling section. Below is a sample response:

[  
  {  
   "objectId": "609CEE02-174E-2486-FFD1-2AAE48B89100",  
   "latitude": 41,  
   "longitude": 2,  
   "categories": [  
     "Restaurants"  
   ],  
   "metadata": {  
     "foo": "bar"  
   }  
  },  
  {  
    "objectId": "80ED18EB-D53B-5E68-FFC0-EA341C213F00",  
    "latitude": 41,  
    "longitude": -87,  
    "categories": [  
      "Restaurants"  
    ],  
    "metadata": {  
      "foo": "bar"  
    }  
  }  
]

Running Search Queries

The geo query object includes multiple parameters, none of them are required. As a result, depending on which parameters contain values, the semantics of the search would change. Any search must be performed within at least one category. If no category names are provided, the search is performed in the Default category.

Search in categories with radius

Radius-based search establishes a circular area by setting the coordinates of a central point and a distance (radius). Backendless searches for geo points in the specified distance from the coordinates in the center and includes them into the search result. The value of the distance is interpreted based in the units parameter, which can be METERS, KILOMETERS, MILES, YARDS, FEET:

curl -X GET \  
-v "http://api.backendless.com/XXXX-XXXX-XXXX/ZZZZ-ZZZZ-ZZZZ/geo/points?lat=41.48&lon=2.15&r=10000&units=METERS&categories=Restaurants"

Search in categories with radius and metadata

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

curl -X GET \  
-v "http://api.backendless.com/XXXX-XXXX-XXXX/ZZZZ-ZZZZ-ZZZZ/geo/points?lat=41.48&lon=2.15&r=10000&units=METERS&categories=Restaurants&metadata=%7B%22Cuisine%22%3A%22French%22%2C%20%22Atmosphere%22%3A%22Romantic%22%7D"

Using dates in where clause when searching in radius

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 condition:

curl -X GET \  
-v "http://api.backendless.com/XXXX-XXXX-XXXX/ZZZZ-ZZZZ-ZZZZ/geo/points?lat=41.48&lon=2.15&r=10000&units=METERS&categories=Restaurants?where=updated<1421234854999"

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.