# Location

## Request location sharing

`client.chats.location.request(stringchatID, RequestOptionsoptions?): LocationRequestResponse`

**post** `/v3/chats/{chatId}/location/request`

Send a location sharing request to a contact. They will receive an iMessage
prompt asking them to share their location.

Location requests only work in **1:1 iMessage chats** (Apple limitation).
Attempting to request location in a group chat, or in an SMS or RCS chat,
returns `409` (Operation not supported on this chat's service type).

### Parameters

- `chatID: string`

### Returns

- `LocationRequestResponse`

  - `message: string`

  - `success: boolean`

### Example

```typescript
import LinqAPIV3 from '@linqapp/sdk';

const client = new LinqAPIV3({
  apiKey: process.env['LINQ_API_V3_API_KEY'], // This is the default and can be omitted
});

const locationRequestResponse = await client.chats.location.request(
  '975d0776-bd17-4273-8337-f346b4c661b0',
);

console.log(locationRequestResponse.message);
```

#### Response

```json
{
  "success": true,
  "message": "Location request sent"
}
```

## Get location data

`client.chats.location.retrieve(stringchatID, RequestOptionsoptions?): GetChatLocationResponse`

**get** `/v3/chats/{chatId}/location`

Retrieve the current location for contacts sharing with you in a chat.

Returns a [GeoJSON](https://datatracker.ietf.org/doc/html/rfc7946) `FeatureCollection`
with a `Feature` for each participant actively sharing their location.

Works for both 1:1 and group chats. In group chats, returns a separate feature for
each participant who is sharing. Each feature's `properties.handle` identifies the user.

Returns an empty `features` array if no one is sharing or no location data is available yet.

### Parameters

- `chatID: string`

### Returns

- `GetChatLocationResponse`

  - `data: Data`

    - `features: Array<Feature>`

      - `geometry: Geometry`

        - `coordinates: Array<number>`

          [longitude, latitude] or [longitude, latitude, altitude]

        - `type: "Point"`

          - `"Point"`

      - `properties: Properties`

        - `handle: string`

          Phone number or email of the person sharing their location

        - `address?: string`

          Full street address

        - `locality?: string`

          City or locality name

        - `updated_at?: string`

          When the location was last updated

      - `type: "Feature"`

        - `"Feature"`

    - `type: "FeatureCollection"`

      - `"FeatureCollection"`

  - `success: boolean`

### Example

```typescript
import LinqAPIV3 from '@linqapp/sdk';

const client = new LinqAPIV3({
  apiKey: process.env['LINQ_API_V3_API_KEY'], // This is the default and can be omitted
});

const getChatLocationResponse = await client.chats.location.retrieve(
  '975d0776-bd17-4273-8337-f346b4c661b0',
);

console.log(getChatLocationResponse.data);
```

#### Response

```json
{
  "error": {
    "status": 400,
    "code": 1002,
    "message": "Phone number must be in E.164 format",
    "doc_url": "https://docs.linqapp.com/error/codes/1xxx/1002/"
  },
  "success": false
}
```

## Domain Types

### Get Chat Location Response

- `GetChatLocationResponse`

  - `data: Data`

    - `features: Array<Feature>`

      - `geometry: Geometry`

        - `coordinates: Array<number>`

          [longitude, latitude] or [longitude, latitude, altitude]

        - `type: "Point"`

          - `"Point"`

      - `properties: Properties`

        - `handle: string`

          Phone number or email of the person sharing their location

        - `address?: string`

          Full street address

        - `locality?: string`

          City or locality name

        - `updated_at?: string`

          When the location was last updated

      - `type: "Feature"`

        - `"Feature"`

    - `type: "FeatureCollection"`

      - `"FeatureCollection"`

  - `success: boolean`

### Location Request Response

- `LocationRequestResponse`

  - `message: string`

  - `success: boolean`
