An object that is or contains a lng-lat position.
Optionaloptions: GetPositionOptions
How to 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.
It normalizes the input to a standard GeoJSON Position, a lng-lat coordinate array. It accepts:
[lng, lat]With
main-when-available, a place with no entry point typed'main'uses its first untyped one, as reverse geocoding returns them. GetPositionEntryPointOption has the full rule.