# EV reachable area

REST API, Service version 1.0.0

> API reference: [`POST /evreachablearea/1.0`](https://benomad.com/dev/doc/bemap-api/api/electric-mobility/evreachablearea.md)

Perform a calculation of reachable area dedicated to electrical vehicle. This service return a geometry of area.

## Summary
1. Request
 1. Parameters
2. Response
 1. Details of fields
 2. Response samples
 3. ErrorResponse object

## Request
The request must be sent with the HTTP method `POST` and the HTTP header `Content-Type` set to `application/json`. 

Sample:
URI: `/bgis/service/evreachablearea/1.0` for JSON output format.
URI: `/bgis/service/evreachablearea/1.0/kml` for KML output format.

POST data:
```javascript
{
  "geoserver": "here",
  "vehicle": "e16f0d0b-964b-4a23-bd78-f5cb438abad6",
  "initBatLvl": 25,
  "temperature": 20,
  "payload": 75,
  "startLon": 2.34494,
  "startLat": 48.78852,
  "geo": true
}
```

All coordinates are defined by longitude and latitude, see the [coordinate system](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md) glossary for more details.

### __Parameters__

- `vehicle` (string, required): Vehicle model (UUID key).
- `temperature` (integer (int32), required): Temperature in Celsius.
- `startLon` (number (double), required): Departure longitude in decimal degrees (WGS84). Also accepted as `longitude`.
- `startLat` (number (double), required): Departure latitude in decimal degrees (WGS84). Also accepted as `latitude`.
- `geoserver` (string): Geoserver name.
- `swidx` (integer (int32), deprecated): Switch index.
- `initBatLvl` (number (double)): Initial battery level in percent. Available value 0 to 100. 100% if not defined.
- `weather` (boolean): Enable the weather information.
- `wp` (string): Enable the weather information.
- `payload` (integer (int32)): Vehicle's extra load (consumables or passengers weight for example) (in kg). 75kg by default.
- `extraPayload` (integer (int32), deprecated): Additional load weight in kg (like passengers, luggage or tools). Deprecated and not supported anymore, use the `payload` field. Also accepted as `extraPayLoad`.
- `criterias` (enum[]): This field is a list of criteria used by the routing calculator, e.g.: "`AVOID_MOTORWAYS`", "`AVOID_TOLLS`".
  - `AVOID_FERRIES`: Find a route with no ferry.
  - `AVOID_MOTORWAYS`: Find a route without motorways.
  - `AVOID_TOLLS`: Find a route with no toll.
  - `AVOID_UNPAVED`: Find a route with no unpaved roads.
  - `AVOID_CROSSING_BORDER`: Find a route without country border crossing (makes sence only when the start and stop points are in the same country).
  - `LESS_EXPENSIVE`: Find the less expensive charging stations. Only with algorithm v2. Deprecated.
  - `TRAFFIC`: Use traffic info for route calculation.
- `stopLon` (number (double)): Arrival longitude in decimal degrees (WGS84).
- `stopLat` (number (double)): Arrival latitude in decimal degrees (WGS84).
- `geo` (boolean): Set to `true` to enable the geometry of the reachable area's polygon. By default `true`.
- `egeo` (boolean): Set to `true` to enable the encoded geometry of the reachable area's polygon. By default `false`. See `Google Encoded Polyline Algorithm Format` in glossary.

## Response

### Details of fields

- `boundingBox` (BoundingBox): The bounding box of the returned polygon geometry.
  - `minLon` (number (double)): Minimum longitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
  - `minLat` (number (double)): Minimum latitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
  - `maxLon` (number (double)): Maximum longitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
  - `maxLat` (number (double)): Maximum latitude, in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)).
- `geometry` (Coordinate[]): The reachable area's polygon geometry defined as a list of WGGS84 coordinates.
  - `lon` (number (double), required): Longitude in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). Also accepted as `longitude`.
  - `lat` (number (double), required): Latitude in degrees decimal ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). Also accepted as `latitude`.
- `encodedGeometry` (string): The reachable area's polygon geometry encoded with Google Algorithm.

See chapter [Google Encoded Polyline Algorithm Format](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-google-encoded-polyline-algorithm-format.md) for full description of encoding format.

### Response samples

JSON Sample (trunked):
```javascript
{
  "boundingBox": {
    "minLon": 1.74877,
    "minLat": 48.39662,
    "maxLon": 2.9994,
    "maxLat": 49.23037
  },
  "geometry": [
    {
      "lon": 2.10434,
      "lat": 48.55356
    },
  . . .
    {
      "lon": 2.03813,
      "lat": 48.53885
    }
  ]
}
```

### ErrorResponse object
If an error occurs during the process on server side, only an error object will be returned in the response. See `Error example` chapter.
* `code`: error code. See the Error list chapter. 
* `message`: error message. 
* `coordinate`: coordinate of error (optional). 
   * `lon`: longitude of coordinate in decimal degrees ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). 
   * `lat`: latitude of coordinate in decimal degrees ([WGS84](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md)). 

#### Error codes
List of all possible error codes:

| Code | Description |
|------|-------------|
| OK | No error. |
| COORDINATE_NOT_MATCH | One of input point cannot be matched on a road. |
| COUNTRY_NOT_AVAILABLE | Start and end addresses coordinates are not in the allowed area. |
| CHARGING_STATION_NOT_FOUND | Cannot find any charging station around the coordinate. |
| NO_REACHABLE_STEP_POINT | No charging stations found can be reached. |
| CANNOT_PERFORM_ROUTING | The routing calculation cannot be performed. |
| OVER_ALLOWED_DISTANCE | The requested travel is over the allowed distance limit. Max distance for journey is 2500 km. |
| INTERNAL_ERROR | The server cannot perform the routing calculation due to internal BeNomad SDK error. |

#### Error example
```javascript
{ 
   "error": { 
      "code": "NO_REACHABLE_STEP_POINT", 
      "message": "All charging stations found cannot be reachable. Around this coordinate.", 
      "coordinate": { 
         "lon": 8.193691832353528, 
         "lat": 45.42630127240513 
      } 
   } 
}
```

All coordinates are defined by longitude and latitude, see the [coordinate system](https://benomad.com/dev/doc/bemap-api/guides/reference/glossary-coordinate-system.md) glossary for more details.
