Filtering Near a Point

Filtering Near a Point

Using the Backend Services RESTful API, you can filter a content type that contains a Geo Point to get all content items that are near it. The result items are ordered by distance and are always limited to 100 items. If you need to return more than 100 items, use withinCenterSphere.


//Ajax request using jQuery
var filter = {
    "Location": {
        "$nearSphere": {
            "longitude": 23.379068,
            "latitude": 42.650601
        }
    }
}
$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/type-name',
    type: "GET",
    headers: {
        "Authorization" : "Bearer your-access-token-here",
        "X-Everlive-Filter": JSON.stringify(filter)
    },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    GET https://api.everlive.com/v1/your-app-id/type-name 
Header:
    Authorization  Bearer your-access-token-here
    X-Everlive-Filter{
        "Location": {
            "$nearSphere": {
                "longitude": 23.379068,
                "latitude": 42.650601
            }
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json

To limit the query by a max distance introduce one of these properties.

$maxDistanceInKilometers - specifies a maximum distance from a geo point in kilometers. $maxDistanceInMiles - specifies a maximum distance from a geo point in miles. $maxDistance- specifies maximum distance in radians.

The results will still be ordered by distance from the given geo point

Note: $maxDistanceInKilometers and $maxDistanceInMiles are applicable only for Earth coordinates as they take into account the Earth's radius.

Distance from a point in kilometers

To retrieve all content items that are within a distance of 5 kilometers from a given geo point named Location execute the following query:

//Ajax request using jQuery
var filter = {
    "Location":  {
        "$nearSphere": {
            "longitude": 23.379068,
            "latitude": 42.650601
        },
        "$maxDistanceInKilometers": 5
    }
};

$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/type-name',
    type: "GET",
    headers: {"Authorization" : "Bearer your-access-token-here",
               "X-Everlive-Filter": JSON.stringify(filter) },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    GET https://api.everlive.com/v1/your-app-id/type-name
Header:
    Authorization  Bearer your-access-token-here
    X-Everlive-Filter {
        "Location":  {
            "$nearSphere": {
                "longitude": 23.379068,
                "latitude": 42.650601
            },
            "$maxDistanceInKilometers": 5
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json

Distance from a point in miles

To retrieve all content items that are within a distance of 5 miles from a given geo point named Location execute the following query:

//Ajax request using jQuery
var filter = {
    "Location": {
        "$nearSphere": {
            "longitude": 23.379068,
            "latitude": 42.650601
        },
        "$maxDistanceInMiles": 5
    }
};

$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/type-name',
    type: "GET",
    headers: {
        "Authorization" : "Bearer your-access-token-here",
        "X-Everlive-Filter" : JSON.stringify(filter)
    },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    GET https://api.everlive.com/v1/your-app-id/type-name
Header:
    Authorization  Bearer your-access-token-here
    X-Everlive-Filter  {
        "Location": {
            "$nearSphere": {
                "longitude": 23.379068,
                "latitude": 42.650601
            },
            "$maxDistanceInMiles": 5
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json

Distance from a point in radians

To retrieve all content items that are within a distance of 0.01 radians from a given geo point named Location execute the following query:

//Ajax request using jQuery
var filter = {
    "Location":  {
        "$nearSphere": {
            "longitude": 23.379068,
            "latitude": 42.650601
        },
        "$maxDistance": 5
    }
};
$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/type-name,
    type: "GET",
    headers: {
        "Authorization" : "Bearer your-access-token-here",
        "X-Everlive-Filter" : JSON.stringify(filter)
    },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
})
Request:
    GET https://api.everlive.com/v1/your-app-id/type-name
Header:
    Authorization  Bearer your-access-token-here
    X-Everlive-Filter {
        "Location":  {
            "$nearSphere": {
                "longitude": 23.379068,
                "latitude": 42.650601
            },
            "$maxDistance": 5
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json
Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.