On Geospatial Value

Geospatial queries

You can run queries on Geospatial data. Examples in this section will use the following sample data:

name

location

string

Geopoint

Munich

[11.574, 48.143]

Athens

[23.729, 37.985]

Amsterdam

[4.895, 52.373]

Vienna

[16.375, 48.208]

Examples

You can use different queries to work with your geopoints data. This can be handy when you’re developing an app with GPS services. The query itself must be placed in the where parameter:
curl -X GET
  -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" 
  -d 'where={/* some query */}' 
  https://api.appery.io/rest/1/db/collections/cities/
80 miles diameter around Vienna:
{
    "location" : {
      "$nearSphere" : [16.373, 48.208],
      "$maxDistanceInMiles" : 80
  }
}
[
    {
        "location":[
            48.208,
            16.373
        ],
        "name":"Vienna"
    }
]
550 kilometers diameter around Vienna:
{
  "location" : {
      "$nearSphere" : [16.373, 48.208],
      "$maxDistanceInKilometers" : 550
  }
}
[
    {
        "location":[
            48.208,
            16.373
        ],
        "name":"Vienna"
    },
    {
        "location":[
            48.143,
            11.574
        ],
        "name":"Munich"
    }
]
(0.21 radians [1350 km] diameter around Vienna:
{
  "location" : {
      "$nearSphere" : [16.373, 48.208],
      "$maxDistanceInRadians" : 0.211897661
  }
}
[
    {
        "location":[
            48.208,
            16.373
        ],
        "name":"Vienna"
    },
    {
        "location":[
            48.143,
            11.574
        ],
        "name":"Munich"
    },
    {
        "location":[
            37.985,
            23.729
        ],
        "name":"Athens"
    }
]
Nearest to Vienna without distance limit:
{
  "location" : {
      "$nearSphere" : [16.373, 48.208]
  }
}
[
    {
        "location":[
            48.208,
            16.373
        ],
        "name":"Vienna"
    },
    {
        "location":[
            48.143,
            11.574
        ],
        "name":"Munich"
    },
    {
        "location":[
            37.985,
            23.729
        ],
        "name":"Athens"
    },
    {
        "location":[
            52.373,
            4.895
        ],
        "name":"Amsterdam"
    }
]
Cities within a box [by SW and NE corners], [11,48] – SW, [20,50] – NE):
{
  "location" : {
    "$geoWithin" : {
      "$box" : [[11, 48],[20, 50]]
    }
  }
}
[
    {
        "location":[
            48.208,
            16.373
        ],
        "name":"Vienna"
    },
    {
        "location":[
            48.143,
            11.574
        ],
        "name":"Munich"
    }
]
Cities within a circle, with the center in Bratislava and a diameter of 100 kms:
{
  "location" : {
    "$geoWithin" : {
      "$centerSphere" : [[17.107, 48.145], 0.015696123]
    }
  }
}
[
    {
        "location":[
            48.208,
            16.373
        ],
        "name":"Vienna"
    },
    {
        "location":[
            48.143,
            11.574
        ],
        "name":"Munich"
    }
]