search by radius in data with geopoint relationship

Hi,

I see there is now geopoint relationship, which is nice.

My question is, how can I do search in geopoints and received data associated? I need to retrieve data from tabled, but search by geopoint.

hope the question is clear.

Hi Janis.

It is a very good question.
There are several samples for you:

  1. Add data object with geo point (as relation):
curl -X GET -H 'application-id : <your app id>' -H 'secret-key : <your secret key>' 
-X POST -v "http://api.backendless.com/v1/data/table" -d '{"relation":{"___class":"GeoPoint","latitude":38.53,"longitude":77.01}}'
  1. For example, you can run next query to find data objects:
curl -X GET -H 'application-id : <your app id>' -H 'secret-key : <your secret key>'  https://api.backendless.com/v1/data/table?where=relation.categories='Default' OR relation.latitude='1'

Encoded query looks like this:

curl -X GET -H 'application-id : <your app id>' -H 'secret-key : <your secret key>'  https://api.backendless.com/v1/data/table?where=relation.categories%3D'Default'%20OR%20relation.latitude%3D'1'

In “whereClause” you can run search by metadata, latitude, longitude, categories…

Regards,
Kate.

There are samples for search by radius:

  1. Add several data objects with relation to geo point:
    one:
-H application-id:application-id-value-from-console
-H secret-key:secret-key-value-from-console 
-H Content-Type:"application/json" 
-H application-type:REST 
-X POST
-v "[url=http://api.backendless.com/v1/data/Person]http://api.backendless.com/v1/data/Person"[/url]; 
-d '{"name":"Bob", "age":33, "phoneNumber":"512-555-1212", "coordinates": {"___class":"GeoPoint","latitude":30.26715,"longitude":-97.74306,"categories":["Home"],"metadata":{"description":"Bob's home"}}}'

two:

-H application-id:application-id-value-from-console
-H secret-key:secret-key-value-from-console 
-H Content-Type:"application/json" 
-H application-type:REST 
-X POST
-v "[url=http://api.backendless.com/v1/data/Person]http://api.backendless.com/v1/data/Person"[/url]; 
-d '{"name":"Jane", "age":28, "phoneNumber":"281-555-1212", "coordinates": {"___class":"GeoPoint","latitude":29.76328,"longitude":-95.36327,"categories":["Home"],"metadata":{"description":"Jane's home"}}}'
  1. Suppose you need to find all Friends who live within certain radius from a given point. This can be accomplished by the following condition specified in the where clause:For example:
distance( 30.26715, -97.74306, coordinates.latitude, coordinates.longitude ) < mi(200)

The semantic of the “distance” function is:

distance(
center point latitude,
center point longitude,
columnname which contains geo point.latitude,
columnname which contains geo point.longitude ) “comparison operator” units-function(value)

where

  • comparison operator can be <, >, =, >=, <=
  • units-function: ft(), km(), mi(), yd()

The request returns all data objects for which the “coordinates” column contains a geo point within the distance identified by the “distance” function:


-H application-id:application-id-value-from-console
-H secret-key:secret-key-value-from-console 
-H Content-Type:"application/json" 
-H application-type:REST 
-X GET
-v "[url=http://api.backendless.com/v1/data/Person?where=distance(%2030.26715%2C%20-97.74306%2C%20coordinates.latitude%2C%20coordinates.longitude%20)%20%3C%20mi(200)]http://api.backendless.com/v1/data/Person?where=distance(%2030.26715%2C%20-97.74306%2C%20coordinates.latitude%2C%20coordinates.longitude%20)%20%3C%20mi(200)"[/url];

thsnks will do this way