> For the complete documentation index, see [llms.txt](https://docs.digit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digit.org/local-governance/v2.7/platform/configure-digit/services-overview/core-services/location-services.md).

# Location Services

## Overview

A core application which provides location details of the tenant for which the services are being provided.

## Pre-requisites

Before you proceed with the documentation, make sure the following pre-requisites are met -

* Java 8
* PSQL server is running and a database is created
* Knowledge of egov-mdms service
* egov-mdms service is running and all the required mdms master are loaded in it

## Key Functionalities

* The location information is also known as boundary data of ULB
* Boundary data can be of different hierarchies ADMIN, ELECTION hierarchy which is defined by the Administrators, Revenue hierarchy defined by the Revenue department.
* The election hierarchy has the locations divided into several types like zone, election ward, block, street and locality. The Revenue hierarchy has the locations divided into a zone, ward, block and locality.
* The model which defines the localities like zone, ward and etc is a boundary object which contains information like name, lat, long, parent or children boundary if any. The boundaries come under each other in a hierarchy - a zone contains wards, a ward contains blocks, and a block contains locality. The order in which the boundaries are contained in each other will differ based on the tenants.

| Environmental Variables             | Description                                     |
| ----------------------------------- | ----------------------------------------------- |
| egov.services.egov\_mdms.hostname   | Host name for MDMS service.                     |
| egov.services.egov\_mdms.searchpath | MDMS Search URL.                                |
| egov.service.egov.mdms.moduleName   | MDMS module which contain boundary master.      |
| egov.service.egov.mdms.masterName   | MDMS master file which contain boundary detail. |

## Deployment Details

1. Add/Update the mdms master file which contains boundary data of ULB’s.
2. Add Role-Action mapping for egov-location APIs.
3. Deploy/Redeploy the latest version of egov-mdms service.
4. Fill the above environment variables in egov-location with proper values.
5. Deploy the latest version of egov-location service.

## Configuration Details

The boundary data has been moved to mdms from the master tables in DB. The location service fetches the JSON from mdms and parses it to the structure of boundary object as mentioned above. A sample master would look like below.

```
{
  "tenantId": "pg.cityA",
   "moduleName": "egov-location",
  "TenantBoundary": [
  {
      "hierarchyType": {
              "code": "ADMIN",
              "name": "ADMIN"
      },
       "boundary": {
                "id": 1,
                "boundaryNum": 1,
                "name": "CityA",
                "localname": "CityA",
                "longitude": null,
                "latitude": null,
                "label": "City",
                "code": "pg.cityA",
                "children": []
        }

    }
 ]
}
```

| Attribute Name                    | Description                                                                   |
| --------------------------------- | ----------------------------------------------------------------------------- |
| tenantId                          | The tenantId (ULB code) for which the boundary data configuration is defined. |
| moduleName                        | The name of the module where TenantBoundary master is present.                |
| TenantBoundary.hierarchyType.code | Unique code of the hierarchy type.                                            |
| TenantBoundary.hierarchyType.name | Unique name of the hierarchy type.                                            |
| TenantBoundary.boundary.id        | Id of boundary defined for particular hierarchy.                              |
| boundaryNum                       | Sequence number of boundary attribute defined for the particular hierarchy.   |
| name                              | Name of the boundary like Block 1 or Zone 1 or City name.                     |
| localname                         | Local name of the boundary.                                                   |
| longitude                         | Longitude of the boundary.                                                    |
| latitude                          | Latitude of the boundary.                                                     |
| label                             | Label of the boundary.                                                        |
| code                              | Code of the boundary.                                                         |
| children                          | Details of its sub-boundaries.                                                |

## Integration

### Integration Scope

The egov-location API’s can be used by any module which needs to store the location details of the tenant.

### Integration Benefits

* Get the boundary details based on boundary type and hierarchy type within the tenant boundary structure.
* Get the geographical boundaries by providing appropriate GeoJson.
* Get the tenant list in the given latitude and longitude.

### Steps to Integration

1. To integrate, host of egov-location should be overwritten in helm chart.
2. /boundarys/\_search should be added as the search endpoint for searching boundary details based on tenant Id, Boundary Type, Hierarchy Type etc.
3. /geography/\_search should be added as the search endpoint .This method handles all requests related to geographical boundaries by providing appropriate GeoJson and other associated data based on tenantId or lat/long etc.
4. /tenant/\_search should be added as the search endpoint. This method tries to resolve a given lat, long to a corresponding tenant, provided there exists a mapping between the reverse geocoded city to tenant.
5. The MDMS Tenant boundary master file should be loaded in MDMS service.

## Reference Docs

### Doc Links

| Title       | Link                                                                                                                      |
| ----------- | ------------------------------------------------------------------------------------------------------------------------- |
| Local setup | <https://github.com/egovernments/core-services/blob/669c94194911ada92b6cb3c87e5fad7a7478cc6a/egov-location/LOCALSETUP.md> |

### API List

| Title               | Link                                                                                                                                   |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| /boundarys/\_search | <https://github.com/egovernments/core-services/blob/master/egov-location/postman/BoundaryNewVersion11Endpoint.postman_collection.json> |
| /geography/\_search | <https://github.com/egovernments/core-services/blob/master/egov-location/postman/BoundaryNewVersion11Endpoint.postman_collection.json> |
| /tenant/\_search    | <https://github.com/egovernments/core-services/blob/master/egov-location/postman/BoundaryNewVersion11Endpoint.postman_collection.json> |

Please refer to the [Swagger API contract](https://editor.swagger.io/?url=https://raw.githubusercontent.com/egovernments/egov-services/master/docs/egov-location/contracts/v11-0-0.yml#!/) for egov-location service to understand the structure of APIs and to have a visualisation of all internal APIs.

[![Creative Commons License](https://i.creativecommons.org/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)All content on this page by [eGov Foundation ](https://egov.org.in/)is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digit.org/local-governance/v2.7/platform/configure-digit/services-overview/core-services/location-services.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
