This is the documentation of version 0.48.3. Go to the latest version, 1.0.0-rc.5.

Coordinates

Working with Coordinates

getPosition

Extracts lng-lat coordinates from various input formats into a standard GeoJSON Position array [longitude, latitude].

Supported input formats:

import { getPosition } from '@tomtom-org/maps-sdk/core';

// From coordinate array
const pos1 = getPosition([4.9, 52.3]);
// Returns: [4.9, 52.3]

// From Point geometry
const pos2 = getPosition({
  type: 'Point',
  coordinates: [4.9, 52.3]
});
// Returns: [4.9, 52.3]

// From a Place Feature
const place = await geocode({ key: 'your-api-key', query: 'Amsterdam' });
const pos3 = getPosition(place);
// Returns: [longitude, latitude]

// From a Place with entry point preference
const pos4 = getPosition(place, { useEntryPoint: 'main-when-available' });
// Returns entry point coordinates if available, otherwise geometry coordinates

Entry point options:

When working with Places that have entry points (building entrances), you can specify which position to extract:

Returns: Position | null – The coordinates as [longitude, latitude], or null if input is invalid.