Filtering within a Circle

Filter within a Circle

You can retrieve all content type items that are located within a circle with a radius in either kilometers, miles, or radians.

Filtering within a circle with radius in kilometers

To retrieve all content items that are placed within a circle with radius 5 kilometers execute the following query:

//Ajax request using jQuery
var filter = {
    "Location": {
        "$within": {
            "$centerSphere": {
                "center": {
                    "longitude": 23.379068, "latitude": 42.650601
                },
                "radiusInKilometers": 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": {
            "$within": {
                "$centerSphere": {
                    "center": {
                        "longitude": 23.379068, "latitude": 42.650601
                    },
                    "radiusInKilometers": 5
                }
            }
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json

Filtering within a circle with radius in miles

To retrieve all content items that are placed within a circle with radius 5 miles execute the following query:

//Ajax request using jQuery
var filter = {
    "Location": {
        "$within": {
            "$centerSphere": {
                "center": {
                    "longitude": 23.379068, "latitude": 42.650601
                },
                "radiusInMiles": 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": {
            "$within": {
                "$centerSphere": {
                    "center": {
                        "longitude": 23.379068, "latitude": 42.650601
                    },
                    "radiusInMiles": 5
                }
            }
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json

Filtering within a circle with radius in radians

To retrieve all content items that are placed within a circle with radius 0.01 radians execute the following query:


//Ajax request using jQuery
var filter = {
    "Location": {
        "$within": {
            "$centerSphere": {
                "center": {
                    "longitude": 23.379068, "latitude": 42.650601
                },
                "radius": 5
            }
        }
    }
};
$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/type-name',
    type: "GET",
    headers: {"Authorization" : "Bearer your-access-token-here"},
    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": {
            "$within": {
                "$centerSphere": {
                    "center": {
                        "longitude": 23.379068, "latitude": 42.650601
                    },
                    "radius": 5
                }
            }
        }
    }
Response:
    Status: 200 OK
    Content-Type: application/json

Note: A circle can also be described as an array of two elements, the first one being the center and the second one radius. In that case the radius is assumed to be in radians.

The difference between $centerSphere and $nearSphere queries is that $centerSphere doesn't return the results ordered by distance from the center point, whereas $nearSphere does. This makes $centerSphere the favorable choice when performance is a priority.

$centerSphere caveat: At the moment Telerik Platform does not support queries that wrap at the poles. This is especially evident with $centerSphere. If a wrapping occurs with $centerSphere a null result will be returned.

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.