Skip to main content
GuidesAPI ReferenceExamples

Search Assets in Area

|

Find active assets within geographical boundaries using circle, envelope (rectangle), or polygon queries.

Overview

Asset spatial search helps you locate vehicles, equipment, or personnel within specific areas. Only assets with location updates in the past 7 days (active state) are returned.

Use Case

A fleet manager needs to:

  • Find all delivery vans within 1km of a customer location
  • Identify trucks in a specific warehouse zone
  • Locate all assets in a city district (polygon)

Find all logistics vehicles within 1000m of downtown center.

curl -X GET https://api.magiclane.net/api/v1/search_assets_in_area_circle \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"p_center_lon": 25.614433,
"p_center_lat": 45.653820,
"p_radius_m": 1000,
"p_properties": {
"department": "logistics"
},
"p_filter": "all_of",
"p_page_no": 1,
"p_entries_per_page": 20
}'

Search for all assets in a bounding box area.

curl -X GET https://api.magiclane.net/api/v1/search_assets_in_area_envelope \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"p_lonmin": 25.599977,
"p_latmin": 45.642448,
"p_lonmax": 25.633650,
"p_latmax": 45.657558,
"p_properties": {
"vehicle_type": "truck"
},
"p_filter": "all_of",
"p_page_no": 1,
"p_entries_per_page": 20
}'

Find assets within an irregular shaped zone (e.g., city district).

curl -X GET https://api.magiclane.net/api/v1/search_assets_in_area_polygon \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"p_coordinates": [
[25.566809, 45.673419],
[25.560272, 45.658444],
[25.568433, 45.643670],
[25.634891, 45.631630],
[25.662850, 45.654689],
[25.623632, 45.677563],
[25.566809, 45.673419]
],
"p_properties": {},
"p_filter": "any_of",
"p_page_no": 1,
"p_entries_per_page": 20
}'

Response Example (code 200 OK)

{
"assets": [
{
"id": "vehicle_101",
"name": "Delivery Van 101",
"state": "active",
"properties": {
"department": "logistics",
"vehicle_type": "van",
"zone": "downtown"
},
"last_location": {
"coordinates": [25.614076, 45.648579],
"timestamp": 1766482291,
"speed": 18,
"bearing": 45
}
}
],
"page": {
"total_entries": 1,
"page_no": 1,
"has_more": false
}
}

Example 4: Get All Active Assets with Last Location

Get a complete list of all active assets and their most recent tracked positions.

curl -X GET https://api.magiclane.net/api/v1/get_assets_by_properties \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"p_properties": {},
"p_filter": "all_of",
"p_page_no": 1,
"p_entries_per_page": 100
}'

Response Example:

{
"assets": [
{
"id": "vehicle_101",
"name": "Delivery Van 101",
"state": "active",
"properties": {
"department": "logistics",
"vehicle_type": "van",
"zone": "downtown"
},
"last_location": {
"coordinates": [25.614076, 45.648579],
"speed": 18,
"bearing": 45,
"accuracy": 0.5,
"timestamp": 1766482291
}
},
{
"id": "truck_205",
"name": "Heavy Duty Truck 205",
"state": "active",
"properties": {
"department": "freight",
"vehicle_type": "truck",
"zone": "regional"
},
"last_location": {
"coordinates": [25.60871, 45.647718],
"speed": 15,
"bearing": 25,
"accuracy": 0.5,
"timestamp": 1766482291
}
}
],
"page": {
"total_entries": 2,
"page_no": 1,
"has_more": false
}
}
Best Practices
  • Filtering: Use p_properties to filter by department, zone, or vehicle type for better performance
  • Caching: Cache results for 30-60 seconds to reduce API calls when displaying on dashboards
  • State Check: Only assets with state: "active" (location updated in last 7 days) are returned
Note

This endpoint returns only active assets (those with location updates in the past 7 days). Inactive assets are automatically excluded from results.

Property Filtering

Filter Types

all_of - Asset must match ALL specified properties:

{
"p_properties": {
"department": "logistics",
"vehicle_type": "van",
"zone": "downtown"
},
"p_filter": "all_of"
}

Returns: Only assets that are logistics vans in downtown zone

any_of - Asset must match AT LEAST ONE property:

{
"p_properties": {
"department": "logistics",
"department_alt": "freight"
},
"p_filter": "any_of"
}

Returns: Assets in either logistics OR freight departments

Pagination

Handle large result sets efficiently:

// Page through all results
let page = 1;
let hasMore = true;
const allAssets = [];

while (hasMore) {
const response = await searchAssets({
p_page_no: page,
p_entries_per_page: 100
});

allAssets.push(...response.assets);
hasMore = response.page.has_more;
page++;
}

console.log(`Total assets found: ${allAssets.length}`);

Use Case Examples

Emergency Response

// Find all emergency vehicles near incident
const nearbyVehicles = await searchInCircle({
center: incidentLocation,
radius: 5000, // 5km
properties: { type: 'emergency' }
});

Zone Management

// Check which vehicles are in restricted zone
const unauthorizedVehicles = await searchInPolygon({
coordinates: restrictedZoneCoords,
properties: { authorized: false }
});

Resource Allocation

// Find available delivery vans in city
const availableVans = await searchInEnvelope({
bbox: cityBounds,
properties: {
vehicle_type: 'van',
status: 'available'
}
});