This is the documentation of version 1.0.0-rc.1. Go to the latest version, 1.0.0-rc.5.
TomTom Maps for JavaScript
    Preparing search index...

    Function getPosition

    • 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:

      • Raw coordinate arrays [lng, lat]
      • GeoJSON Point geometries
      • GeoJSON Point Features, including Places with entry points

      Parameters

      • hasLngLat: HasLngLat | undefined

        An object that is or contains a lng-lat position.

      • Optionaloptions: GetPositionOptions

        How to extract the position.

      Returns Position | null

      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