# Geolocation

> Geographic coordinates with latitude, longitude, altitude, and accuracy.

- Name: `geolocation`
- Categories: common
- Detail page: https://open-types.dev/types/geolocation

## Install

```bash
# Types only
npx shadcn add @open-types/geolocation

# Types + Zod v4 validators
npx shadcn add @open-types/geolocation-zod

# Types + real-world examples
npx shadcn add @open-types/geolocation-examples
```

## Types

```typescript
export interface Geolocation {
  latitude: number;
  longitude: number;
  altitude?: number;
  accuracy?: number;
  heading?: number;
  speed?: number;
  timestamp?: number;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type { Geolocation } from "../types/geolocation";

export const geolocationSchema = z.object({
  latitude: z.number().min(-90, { error: "Latitude must be at least -90" }).max(90, {
    error: "Latitude must be at most 90",
  }),
  longitude: z.number().min(-180, { error: "Longitude must be at least -180" }).max(180, {
    error: "Longitude must be at most 180",
  }),
  altitude: z.number().optional(),
  accuracy: z.number().min(0, { error: "Accuracy cannot be negative" }).optional(),
  heading: z.number().min(0, { error: "Heading must be at least 0" }).max(360, {
    error: "Heading must be at most 360",
  }).optional(),
  speed: z.number().min(0, { error: "Speed cannot be negative" }).optional(),
  timestamp: z.number().optional(),
}) satisfies z.ZodType<Geolocation>;

export type { Geolocation } from "../types/geolocation";
```

## Examples

```typescript
// Source: hand-crafted; coords correspond to public landmarks
import type { Geolocation } from "../types/geolocation";

export const geolocationExamples = {
  fullGps: {
    latitude: 37.7749,
    longitude: -122.4194,
    altitude: 16,
    accuracy: 5,
    heading: 270,
    speed: 1.4,
    timestamp: 1712948400000,
  } satisfies Geolocation,
  minimal: { latitude: 51.5074, longitude: -0.1278 } satisfies Geolocation,
  highAltitude: {
    latitude: 27.9881,
    longitude: 86.9250,
    altitude: 8848,
    accuracy: 10,
  } satisfies Geolocation,
  stationary: {
    latitude: 35.6762,
    longitude: 139.6503,
    accuracy: 3,
    speed: 0,
    timestamp: 1712948400000,
  } satisfies Geolocation,
  southernHemisphere: {
    latitude: -33.8688,
    longitude: 151.2093,
    accuracy: 8,
  } satisfies Geolocation,
} as const;
```
