Documentation
Feedback
Guides
API Reference

Guides
Master DataMaster Data v2Search by geocoordinates
Search by geocoordinates

To enable search by geocoordinates in Master Data v2, your JSON schema must contain an object with the properties latitude and longitude:


_12
{
_12
"properties": {
_12
"{{yourFieldName}}": {
_12
"type": "object",
_12
"properties": {
_12
"latitude": { "type": "number" },
_12
"longitude": { "type": "number" }
_12
},
_12
"additionalProperties": false
_12
}
_12
}
_12
}

Also, it must be configured as indexed:


_10
{
_10
"v-indexed": [ "{{yourFieldName}}" ]
_10
}

Saving documents

To save a document that can later be searched by geocoordinates, it must contain the object value configured as geocoordinates:


_10
{
_10
"{{yourFieldName}}": {
_10
"latitude": {{value}},
_10
"longitude": {{value}}
_10
}
_10
}

Filtering

To filter documents that contain a location nearby a given geocoordinate (measured in km), add a filter as a query parameter in this format:


_10
{{yourFieldName}}={{latitudeValue}},{{longitudeValue}},{{integer}}km

See an example:


_10
address.location=-23.01227,-43.46163,25km

Ordering search results by distance

To order documents by distance from a given geocoordinate, use the _sort query parameter with this format:


_10
_sort={{yourFieldName}} {{asc/desc}} {{latitudeValue}},{{longitudeValue}} km

See an example


_10
_sort=address.location asc -23.01227,-43.46163 km

When Master Data order results by distance from a geocoordinate field a new field is available: _sort. This field could be added in _fields parameter to retrieve the distance between the geocoordinate in the sort query.

Real complete example

JSON Schema:


_44
{
_44
"properties": {
_44
"name": {
_44
"type": "string"
_44
},
_44
"isActive": {
_44
"type": "boolean"
_44
},
_44
"address": {
_44
"type": "object",
_44
"properties": {
_44
"state": {
_44
"type": "string"
_44
},
_44
"location": {
_44
"type": [
_44
"null",
_44
"object"
_44
],
_44
"properties": {
_44
"latitude": {
_44
"type": "number"
_44
},
_44
"longitude": {
_44
"type": "number"
_44
}
_44
},
_44
"additionalProperties": false
_44
}
_44
}
_44
}
_44
},
_44
"v-indexed": [
_44
"name",
_44
"isActive",
_44
"address"
_44
],
_44
"v-default-fields": [
_44
"id",
_44
"name",
_44
"address",
_44
"_sort"
_44
]
_44
}

Query:


_10
/search?address.location=-23.01227,-43.46163,100km&_schema=v1&_sort=address.location asc -23.01227,-43.46163 km&_fields=id,_sort

Result:


_26
[
_26
{
_26
"id": "AME",
_26
"_sort": [
_26
0
_26
]
_26
},
_26
{
_26
"id": "BAR",
_26
"_sort": [
_26
10.71936198115181
_26
]
_26
},
_26
{
_26
"id": "BAN",
_26
"_sort": [
_26
14.87184710662879
_26
]
_26
},
_26
{
_26
"id": "BRX",
_26
"_sort": [
_26
27.607623540300178
_26
]
_26
}
_26
]

Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page