-
Notifications
You must be signed in to change notification settings - Fork 2
Geofences
A geofence is a user-defined bounded area to trigger Entry and Exit alert of the user/vehicle. Custom areas or places can be created as a Geofence under your account, For example, it could be a hotel, Restaurant, Office, work area, retail store, and so on.
MapmyIndia InTouch SDK supports Point, Circle, and Polygon (Custom Region/Area) geofences. You can Create, Update, or Delete geofences using the below methods. Also, get the total time spent inside the geofence using the below methods.
The create geofence method helps you to create a geofence under your account. Three types of geofence can be created: Point, Circle, Polygon.
Input the Lat, long, and the name of the geofence to create the point geofence. A point geofence has a fixed radius of 100 meters, so the user need not put the radius of the geofence. To customize the radius of geofence refers to the circle geofence method.
// Point type geofence
// ICreateGeoFenceListener - returns success if geofence created else error as callback methods.
InTouch.createGeoFence(<geofence name>, new GeoFencePoint(<Latitude>, <Longitude>), new ICreateGeoFenceListener() {
@Override public void onSuccess() {
// write your code here.
}
@Override public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.createGeoFence(<geofence name>, new GeoFencePoint(<Latitude>, <Longitude>), object: ICreateGeoFenceListener{
override fun onSuccess(response: CreateGeoFenceResponse?) {
// write your code here
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
Create a circle geofence with a radius of your choice. Input Lat, long, Radius, and name of the geofence to create the circle geofence.
// Circle type geofence, the radius will be in meters.
// ICreateGeoFenceListener - returns success if geofence created else error as callback methods.
InTouch.createGeoFence(<geofence name>, new GeoFencePoint(<Latitude>, <Longitude>), <range>, new ICreateGeoFenceListener() {
@Override public void onSuccess(CreateGeoFenceResponse response) {
// write your code here
}
@Override public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
error description gives a message for a particular error.
}
});
InTouch.createGeoFence(<geofence name>, new GeoFencePoint(<Latitude>, <Longitude>), <range>, object: ICreateGeoFenceListener{
override fun onSuccess(response: CreateGeoFenceResponse?) {
// write your code here
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
To draw a polygon geofence we need at least three points. Multiple points can be added to create the custom shape Geofence. Input a list of geofence points (Lat, long) in the comma-separated format.
// Polygon Geofence
// ICreateGeoFenceListener - returns success if geofence created else error as callback methods.
InTouch.createGeoFence(<geofence name>, <list of GeoFencePoint>, new ICreateGeoFenceListener() {
@Override public void onSuccess(CreateGeoFenceResponse response) {
// writeyour code here
}
@Override public void onError(String reason, String identifier, String description) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.createGeoFence(<geofence name>, <list of GeoFencePoint>, object: ICreateGeoFenceListener{
override fun onSuccess(response: CreateGeoFenceResponse?) {
// write your code here
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
1.geoFenceName(String)
- Name of the geofence.
2.geoFencePoint(GeoFencePoint)
- Geofence point(s). List of "GeoFencePoint" for polygon else single object required.
- 201: To denote a successful record is being created.
- 400: Bad Request, User made an error while creating a valid request.
- 401: Unauthorized, the Developer’s key is not allowed to send a request with restricted parameters.
- 403: Forbidden, the Developer’s key has hit its daily/hourly limit.
- 500: Internal Server Error, the request caused an error in our systems.
- 503: Service Unavailable, during our maintenance break or server downtimes.
- 200: Success
- 203: Device Not Found
- 400: Bad Request - Invalid device ID supplied or invalid data type. For example, the input attribute "id" is an integer but string value gets passed.
- 401: Unauthorized Request. Access to API is forbidden.
- 404: Not Found - URL Not Found
CreateGeoFenceResponse
class object returns the API response as a JSON object.
id (Long)
- Id of the newly created geofence.
InTouch Get Geofences methods can be used to request the list of geofence areas using the unique geofence IDs which is being assigned by InTouch.
Get the geofence response with or without shape by setting ignore geometry value as true/false. for example, the type will be either a point, polygon, or circle.
// ignoreGeometry is a boolean value. If the user doesn't need geometry with geofence pass true else false.
// IGetGeoFenceListener- returns all geoFences with geometry in response if success else errors as callback methods.
InTouch.getGeoFences(<ignoreGeometry>, new IGetGeoFenceListener() {
@Override
public void onSuccess(InTouchGeoFenceResponse response){
// write your code here.
}
@Override
public void onError(String reason, String identifier, String description) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.getGeoFences(<ignoreGeometry>, object: IGetGeoFenceListener{
override fun onSuccess(t: InTouchGeoFenceResponse?) {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
Get a geofence with or without the geometry value like circle, polygon, or point. Set ignoreGeometry value as true/false.
// Get single geofence with geometry value
// IGetGeoFenceListener- returns single geoFence with geometry in response if success else error as callback methods.
InTouch.getGeoFences(<id of geofence>,<ignoreGeometry>, new IGetGeoFenceListener() {
@Override
public void onSuccess(InTouchGeoFenceResponse response) {
// write your code here.
}
@Override
public void onError(String reason, String identifier, String description) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.getGeoFences(<id of geofence>,<ignoreGeometry>, object: IGetGeoFenceListener{
override fun onSuccess(t: InTouchGeoFenceResponse?) {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
Get multiple geofences for an array of geofence Ids with ignoreGeometry parameter value set as false.
// Get multiple geofences with geometry value
// IGetGeoFenceListener- returns multiple geoFences in response if success else error as callback methods.
InTouch.getGeoFences(<Long array of geofence ids>,<ignoreGeometry>, new IGetGeoFenceListener() {
@Override
public void onSuccess(InTouchGeoFenceResponse response){
// write yor code here.
}
@Override
public void onError(String reason, String identifier, String description) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.getGeoFences(<Long array of geofence ids>,<ignoreGeometry>, object: IGetGeoFenceListener{
override fun onSuccess(t: InTouchGeoFenceResponse?) {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
1.id(Long)
- Geofence id. Use this if you want to get details of specific multiple geofence IDs.
2.ignoreGeometry(boolean)
- Non-mandatory field, boolean value to fetch geometry details.
- 200: To denote a successful API call.
- 400: Bad Request, User made an error while creating a valid request.
- 401: Unauthorized, the Developer’s key is not allowed to send a request with restricted parameters.
- 403: Forbidden, the Developer’s key has hit its daily/hourly limit.
- 500: Internal Server Error, the request caused an error in our systems.
- 503: Service Unavailable, during our maintenance break or server downtimes.
- 200: Success
- 203: Device Not Found
- 204: No Content Or No Data Found
- 400: Bad Request - Invalid device ID supplied or invalid data type. For example, the input attribute "id" is an integer but the string value gets passed.
- 401: Unauthorized Request. Access to API is forbidden.
- 404: Not Found - URL Not Found
CreateGeoFenceResponse
- Class object returns the API response as a JSON object.
- List<GeoFenceResult>
- List of GeoFenceResult.
-
id(Long)
- Geofence ID -
name(String)
- Name of the geofence -
geometry(Geometry)
- Geofence Geometry object. -
type(String)
- Depending on the type of geofence this value can be Circle(buffer > 50 meters), Polygon or Point(buffer = 50 mtrs) -
buffer(Double)
- Radius(in meters) of a circular geofence -
creationTime(long)
- epoch timestamp in seconds at which the geofence was created. -
updationTime(Long)
- epoch timestamp in seconds at which the geofence was updated.
-
type(String)
-This defines the type of geofence, it can be point or polygon. -
coordinates(Object)
- Geofence geometry coordinates. -
latLng(GeoFencePoint)
- GeoFencePoint object. Use this in case of geofence type "Point or Circle". -
points(List<List<GeoFencePoint>>)
- List of GeoFencePoint list. Use this in case of geofence type "Polygon".
Use Geofence ID to update Geofence name, latitude, longitude, and radius in the below method
Update geofence values like geofence name and lat, long using below method
// update single geofence
// IUpdateGeoFenceListener - returns success if gefence updated successfully, else error as callback methods.
InTouch.updateGeoFence(<geofence id>, <name of geofence>, <GeoFencePoint>, new IUpdateGeoFenceListener() {
@Override
public void onSuccess() {
// write your code here.
}
@Override
public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.updateGeoFence(<geofence id>, <name of geofence>, <GeoFencePoint>, object: IUpdateGeoFenceListener{
override fun onSuccess() {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
Update geofence name, latitude, longitude, and Radius for a circle geofence using the below method.
// update single geofence with buffer value. The buffer is like a radius in meters.
InTouch.updateGeoFence(<geofence id>, <name of geofence>, <GeoFencePoint>, <buffer>, new IUpdateGeoFenceListener() {
@Override
public void onSuccess() {
// write your code here.
}
@Override
public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.updateGeoFence(<geofence id>, <name of geofence>, <GeoFencePoint>, <buffer>, object: IUpdateGeoFenceListener{
override fun onSuccess() {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
Update the geofence name, and the latitude, longitude of the polygon geofence using the below method.
// Update polygon geofence.
InTouch.updateGeoFence(<geofence id>, <name of geofence>, <list of GeoFencePoint>, new IUpdateGeoFenceListener() {
@Override
public void onSuccess() {
// write your code here.
}
@Override
public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.updateGeoFence(<geofence id>, <name of geofence>, <list of GeoFencePoint>, object: IUpdateGeoFenceListener{
override fun onSuccess() {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
-
geoFenceId(Long)
- Id of the existing geofence. -
geoFenceName(String)
- Name of the geofence. If you need to update the existing one then use this else pass null. -
geoFencePoint(GeoFencePoint)
-List of "GeoFencePoint" for polygon geofence else single object required.
- 200: To denote a successful API call.
- 400: Bad Request, User made an error while creating a valid request.
- 401: Unauthorized, the Developer’s key is not allowed to send a request with restricted parameters.
- 403: Forbidden, the Developer’s key has hit its daily/hourly limit.
- 500: Internal Server Error, the request caused an error in our systems.
- 503: Service Unavailable, during our maintenance break or server downtimes.
- 200: Success
- 203: Device Not Found
- 400: Bad Request - Invalid device ID supplied or invalid data type. For example, the input attribute "id" is an integer but string value gets passed.
- 401: Unauthorized Request. Access to API is forbidden.
- 404: Not Found - URL Not Found
UpdateGeoFenceResponse
- Class object returns the API response as a JSON object.
message<String>
- Describes the type of error based on the type of response code.
Delete Geofences by mentioning the geofence IDs in the following methods
Use the below method to delete a particular geofence by mentioning the geofence ID.
// Delete single geofence
// IResultListener- returns success if gefence deleted successfully, else error as callback methods.
InTouch.deleteGeoFence(<geofence id>, new IResultListener() {
@Override public void onSuccess() {
// write your code here.
}
@Override public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.deleteGeoFence(<geofence id>, object: IResultListener{
override fun onSuccess() {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
Use the below method to delete a list of geofence Ids at once.
// Delete multiple geofences
InTouch.deleteGeoFence(<Long array of geofence ids>, new IResultListener() {
@Override public void onSuccess() {
// write your code here.
}
@Override public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.deleteGeoFence(<Long array of geofence ids>, object: IResultListener{
override fun onSuccess() {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
-
geoFenceId(Long)
- Id or array of Ids of existing geofence(s).
- 200: To denote a successful API call.
- 400: Bad Request, User made an error while creating a valid request.
- 401: Unauthorized, the Developer’s key is not allowed to send a request with restricted parameters.
- 403: Forbidden, the Developer’s key has hit its daily/hourly limit.
- 500: Internal Server Error, the request caused an error in our systems.
- 503: Service Unavailable, during our maintenance break or server downtimes.
- 200: Success
- 203: Device Not Found
- 400: Bad Request - Invalid device ID supplied or invalid data type. For example, the input attribute "id" is an integer but string value gets passed.
- 401: Unauthorized Request. Access to API is forbidden.
- 404: Not Found - URL Not Found
The below method helps to fetch the details of all the geofence activities, such as geofence entry time, exit time, etc, and total time spent inside the geofence, which devices perform w.r.t various geofences across a defined date/time range.
InTouch.getGeoFenceActivity(<array of device ids>, <start time>, <end time>, new IGeoFenceActivityListener() {
@Override public void onSuccess(GeoFenceActivityResponse geoFenceActivityResponse) {
// Write your code here.
}
@Override public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.getGeoFenceActivity(<array of device ids>, <start time>, <end time>, object: IGeoFenceActivityListener{
override fun onSuccess(t : GeoFenceActivityResponse?) {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
InTouch.getGeoFenceActivity(<array of device ids>,<array of gefence ids>, <start time>, <end time>, new IGeoFenceActivityListener() {
@Override public void onSuccess(GeoFenceActivityResponse geoFenceActivityResponse) {
// Write your code here.
}
@Override public void onError(String reason, String errorIdentifier, String errorDescription) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
});
InTouch.getGeoFenceActivity(<array of device ids>, <array of gefence ids>, <start time>, <end time>, object: IGeoFenceActivityListener{
override fun onSuccess(t : GeoFenceActivityResponse?) {
// write your code here.
}
override fun onError(reason: String?, errorIdentifier: String?, errorDescription: String?) {
// reason gives the error type.
// errorIdentifier gives information about error code.
// error description gives a message for a particular error.
}
})
-
deviceId(Long[])
- Long array of the device(s) Id(s) for which you want to fetch the geofence activities. -
geofenceId(Long[])
- Long array of the geofence(s) Id(s) for which you want to fetch the geofence activities done by the device. -
startTime(long)
- epoch timestamp in seconds. Start time from where you want to fetch the geofence activities -
endTime(long)
- epoch timestamp in seconds. End time till where you want to fetch the geofence activities
- 200: To denote a successful API call.
- 400: Bad Request, User made an error while creating a valid request.
- 401: Unauthorized, the Developer’s key is not allowed to send a request with restricted parameters.
- 403: Forbidden, the Developer’s key has hit its daily/hourly limit.
- 500: Internal Server Error, the request caused an error in our systems.
- 503: Service Unavailable, during our maintenance break or server downtimes.
GeoFenceActivityResponse
- Class object returns the API response as a JSON object.
- List<GeoFenceActivity>
- List of GeoFenceActivity.
-
entryLongitude(Double)
- Longitude where the particular device entered the geofence. -
entryLatitude(Double)
- Latitude where the particular device entered the geofence. -
exitLongitude(Double)
- Longitude where the particular device exited the geofence. -
exitLatitude(Double)
- Latitude where the particular device exited the geofence. -
entryTimestamp(Integer)
- Time at which the device entered the particular geofence. -
exitTimestamp(Integer)
- Time at which the device exited the particular geofence. -
geofenceName(String)
- Name of the geofence. -
geofenceId(Integer)
- Id of the geofence where the activity took place. -
deviceId(Integer)
- Id of the device which is performing the activities w.r.t the geofence.