How to check if the asset's position is inside a geofence
Allows the user to check in which geofence polygons an asset resides, and how far away it is from the polygons.
In the below example the in parameter represents the asset's GPS position (latitude and longitude)
https://geofencing.hereapi.com/v8/geofence?
apikey=API_KEY
&in=point:50.09960669260986,8.67125687487836;r=15000
&layers=MYTESTLAYER2Note
This example uses a HERE API Key to authenticate your request. For the available authentication options, see the Identity and Access Management Developer Guide.
Response
The response to the request contains information about each geometry that either comprises the asset position or isn't more than the given search radius away from the asset position.
{
"geometries": [
{
"attributes": {
"ID": "1",
"GEOMETRY_ID": "0",
"NAME": "Frankfurt2",
"ABBR": "FRAN"
},
"distance": -15.58,
"nearestLat": 50.09949,
"nearestLon": 8.67113,
"originalLat": 50.09960669260986,
"originalLon": 8.67125687487836,
"layerId": "MYTESTLAYER2",
"geometry": "MULTIPOLYGON(((8.67029 50.09987,8.67192 50.10048,8.67294 50.09966,8.67217 50.09903,8.67176 50.09921,8.67176 50.09921,8.67029 50.09987)))"
}
],
"meta": [
{
"layerId": "MYTESTLAYER2",
"lastUpdateTimeStamp": 1730911589834
}
]
}Below example shows how a multipoint search (via POST request) works for custom objects. GET requests are subject to request-line length limits imposed by load balancers, so searches with many asset positions must use POST. The asset positions are sent in an application/json request body, while authentication and basic configuration parameters (such as in and filter) remain in the query string.
curl -X POST "https://geofencing.hereapi.com/v8/geofence?apikey=API_KEY&in=assetPositions&filter=NAME='Frankfurt2'" \
-H 'Content-Type: application/json' \
--data-raw '{"point":[{"lat":50.09960669260986,"lon":8.67125687487836,"layer":"MYTESTLAYER2","searchRadius":15000}]}'Response:
{
"geometries": [
{
"attributes": {
"ID": "1",
"GEOMETRY_ID": "0",
"NAME": "Frankfurt2",
"ABBR": "FRAN"
},
"distance": -15.58,
"nearestLat": 50.09949,
"nearestLon": 8.67113,
"originalLat": 50.09960669260986,
"originalLon": 8.67125687487836,
"layerId": "MYTESTLAYER2",
"geometry": "MULTIPOLYGON(((8.67029 50.09987,8.67192 50.10048,8.67294 50.09966,8.67217 50.09903,8.67176 50.09921,8.67176 50.09921,8.67029 50.09987)))"
}
],
"meta": [
{
"layerId": "MYTESTLAYER2",
"lastUpdateTimeStamp": 1730911589834
}
]
}Add an identifier to an asset
Use the optional parameter assetID to enhance asset allocation. The sample request assigns assetId of 1111 to the requested geofence.
https://geofencing.hereapi.com/v8/geofence?
apikey=API_KEY
&in=point:50.09960669260986,8.67125687487836;r=15000
&layers=MYTESTLAYER2
&assetId=1111The API response includes the assigned assetId for each asset included in the request.
{
"geometries": [
{
"attributes": {
"ID": "1",
"GEOMETRY_ID": "0",
"NAME": "Frankfurt2",
"ABBR": "FRAN"
},
"distance": -15.58,
"nearestLat": 50.09949,
"nearestLon": 8.67113,
"originalLat": 50.09960669260986,
"originalLon": 8.67125687487836,
"layerId": "MYTESTLAYER2",
"geometry": "MULTIPOLYGON(((8.67029 50.09987,8.67192 50.10048,8.67294 50.09966,8.67217 50.09903,8.67176 50.09921,8.67176 50.09921,8.67029 50.09987)))",
"assetId": "1111"
}
],
"meta": [
{
"layerId": "MYTESTLAYER2",
"lastUpdateTimeStamp": 1730911589834
}
]
}Related information
Updated 2 days ago