Skip to main content

Locate User

Geolocate the user and then track their current location on the map using the GeolocateControl.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.css" />
        <script src="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.js"></script>
        <style>
            body { margin: 0; padding: 0; }

            #map {
                position: absolute;
                top: 0;
                bottom: 0;
                width: 100%;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>

        <script>
            TrimbleMaps.setAPIKey('YOUR_API_KEY_HERE');

      const map = new TrimbleMaps.Map({
        container: 'map', // container id
        style: TrimbleMaps.Common.Style.TRANSPORTATION,
        center: [-96, 37.8], // starting position
        zoom: 3, // starting zoom
      });

      // Add geolocate control to the map.
      map.addControl(
        new TrimbleMaps.GeolocateControl({
          positionOptions: {
            enableHighAccuracy: true,
          },
          trackUserLocation: true,
        })
      );
    </script>
  </body>
</html>
Last updated June 20, 2025.