Geofence API

The Geofence API enables developers to define, update, and query geofencesโ€”virtual boundaries around geographic areas of interest. It supports:

  • Create โ€“ Define a new geofence area
  • Update โ€“ Modify an existing geofence
  • Containsโ€“ Check if a given coordinate falls within a geofence

This API is essential for location-based alerts, restricted zone monitoring, asset tracking, and smart mobility applications.

๐Ÿ”‘ Authentication

  • All requests must include your API key.
  • Header Example:
  • Authorization: X-Authorization-Token (Get your token HERE)

๐ŸŒ Endpoint

1. Create Geofence

  • POST /v4/geofence/create

๐Ÿ“ค Sample Request


curl --location 'https://apihub.latlong.ai/v4/geofence/create.json' --data '{
  "name":"geofence1",
  "geojson":{
    "coordinates":[
      [
        [
          77.55750175149694,
          13.052318591801537
        ],
        [
          77.50495769457018,
          12.987745328784783
        ],
        [
          77.54197737104056,
          12.9173355309442
        ],
        [
          77.65602185823303,
          12.878339742302444
        ],
        [
          77.72528447872816,
          12.92257330790521
        ],
        [
          77.7091630067157,
          13.001126755861733
        ],
        [
          77.61721090709494,
          13.061043416466177
        ],
        [
          77.55750175149694,
          13.052318591801537
        ]
      ]
    ],
    "type": "Polygon"
  }
}'

๐Ÿ“ฆ Sample Response

{ 

  "code": 1001, 

  "status": "success", 

  "data": { 

    "geofence_id": "57daa174-17b1-44d6-abd1-c97129840d5e", 

    "name": "geofence1" 

  } 

}  

2. Update Geofence

  • POST /v4/geofence/update

๐Ÿ“ค Sample Request


curl --location 'https://apihub.latlong.ai/v4/geofence/update.json'  

--data '{ 

    "geofence_id": "57daa174-17b1-44d6-abd1-c97129840d5e", 

    "name": "geofence1", 

    "geojson":{ 

        "coordinates": [ 

          [ 

            [ 

              77.55750175149694, 

              13.052318591801537 

            ], 

            [ 

              77.50495769457018, 

              12.987745328784783 

            ], 

            [ 

              77.54197737104056, 

              12.9173355309442 

            ], 

            [ 

              77.65602185823303, 

              12.878339742302444 

            ], 

            [ 

              77.72528447872816, 

              12.92257330790521 

            ], 

            [ 

              77.7091630067157, 

              13.001126755861733 

            ], 

            [ 

              77.61721090709494, 

              13.061043416466177 

            ], 

            [ 

              77.55750175149694, 

              13.052318591801537 

            ] 

          ] 

        ], 

        "type": "Polygon" 

      } 

}โ€™ 

  

๐Ÿ“ฆ Sample Response

{ 

  "code": 1001, 

  "status": "success", 

  "data": { 

    "geofence_id": "57daa174-17b1-44d6-abd1-c97129840d5e", 

    "updated_at": 1691389832, 

    "name": "geofence1" 

  } 

}   

3. Check Point Within Geofence (contains)

  • GET /v4/geofence/contains

๐Ÿ“ค Sample Request


curl --location โ€˜https://apihub.latlong.ai/v4/geofence/contains.json?geofence_id=57daa174-17b1-44d6-abd1-c97129840d5e&lat=12.975976804797252&long=77.59630898987734&buffer_distance=200' 

๐Ÿ“ฆ Sample Response

{ 

  "code": 1001, 

  "status": "success", 

  "data": { 

    "contains": true, 

    "geofence_id": "57daa174-17b1-44d6-abd1-c97129840d5e", 

    "lat": 12.975976804797252, 

    "long": 77.59630898987734 

  } 

}    

๐Ÿ“ฅ Request Parameters

ParameterTypeDescription
geofence_idStringUnique identifier for the geofence
coordinatesArrayArray of lat/lon points defining a polygon
latitude FloatLatitude of the point to be checked
longitudeFloatLongitude of the point to be checked

๐Ÿง  Features

  • ๐Ÿšš

    Alert when a delivery vehicle enters or exits a zone

  • ๐Ÿญ

    Trigger actions when assets leave industrial boundaries

  • ๐Ÿž๏ธ

    ๏ธ Track whether wildlife or people remain inside protected zones

  • ๐Ÿข

    Geofencing attendance and access control systems

โš ๏ธ Errors

Status CodeMessageDescription
400Missing required parametersMissing or malformed request
401UnauthorizedInvalid or missing API token
404Not foundGeofence ID does not exist
500Internal Server ErrorInternal server issue