An object which either is or contains a lng-lat position.
Optionaloptions: GetPositionOptionsAdditional options to control how we extract the position.
The extracted position as [longitude, latitude], or null if the input is invalid.
// From coordinate array
getPosition([4.9, 52.3]); // Returns: [4.9, 52.3]
// From Point geometry
getPosition({
type: 'Point',
coordinates: [4.9, 52.3]
}); // Returns: [4.9, 52.3]
// From Point Feature
getPosition({
type: 'Feature',
geometry: { type: 'Point', coordinates: [4.9, 52.3] },
properties: {}
}); // Returns: [4.9, 52.3]
// From Place with entry point
const place = {
type: 'Feature',
geometry: { type: 'Point', coordinates: [4.9, 52.3] },
properties: {
entryPoints: [
{ type: 'main', position: [4.901, 52.301] }
]
}
};
getPosition(place, { useEntryPoint: 'main-when-available' });
// Returns: [4.901, 52.301] (entry point instead of geometry)
// Invalid input
getPosition(undefined); // Returns: null
Extracts the lng-lat position from various input formats.
This utility function accepts multiple formats and normalizes them to a standard GeoJSON Position (lng-lat coordinate array). It handles:
[lng, lat]