Overview
  • Authentication
  • Routing APIs
    • Directions API
    • Directions Basic API
    • Distance Matrix API
    • Distance Matrix Basic API
    • Route Optimizer API
    • Fleet Planner API
  • Roads APIs
    • Snap To Road API
    • Nearest Roads API
    • Speed Limits API
  • Places APIs
    • Autocomplete API
    • Place Details API
    • Advance Place Details API
    • Nearby Search API
    • Advance Nearby Search API
    • Photo API
    • Text Search API
    • Address Validation API
    • Geofencing API
    • Elevation API
  • Geocoding
    • Geocoding API
    • Reverse Geocoding API
  • Map Tiles
    • 2D Tiles
      • Overview
      • Vector Tiles API
      • Static Tiles API
    • 3D Tiles
      • Overview and Integration
    • Style Editor
  • Navigation SDKs
    • Navigation SDK - Android
    • Navigation SDK - iOS
  • Map SDKs
    • Map SDK - iOS
    • Map SDK - Android
  • Places SDKs
    • Places SDK - Android
    • Places SDK - iOS
  • Web SDK
    • SDK Setup
    • Adding Markers
    • Events & Controls
    • Static Maps
    • Geolocation
    • Adding Shapes
    • Marker Clustering
    • Heatmap Layer
    • Ground Overlays
    • Custom Overlays
  • Ola Maps MCP
    • MCP Overview
    • Ola Maps MCP Server
  • Street View

Get Current Location using addGeolocateControls

This documentation provides methods for getting, tracking users current location using addGeolocateControls
This provides a button that uses the browser's geolocation API to locate the user on the map.
This has two modes. If trackUserLocation is false (default) the control acts as a button, which when pressed will set the map's camera to target the user location. If the user moves, the map won't update. This is most suited for the desktop. If trackUserLocation is true the control acts as a toggle button that when active the user's location is actively monitored for changes. In this mode the GeolocateControl has three interaction states: * active - the map's camera automatically updates as the user's location changes, keeping the location dot in the center. Initial state and upon clicking the GeolocateControl button. * passive - the user's location dot automatically updates, but the map's camera does not. Occurs upon the user initiating a map movement. * disabled - occurs if Geolocation is not available, disabled or denied.

Example

Use addGeolocateControls to set users location
Programmatically request and move the map to the user's location.

Events

geolocate
This event is triggered when the user's location is successfully retrieved.
error
This event is emitted when there is an error in retrieving the user's location.
trackuserlocationstart
Triggered when tracking of the user's location begins.
trackuserlocationend
Triggered when tracking of the user's location ends.
userlocationfocus
Triggered when the user's location gains focus, such as when a map is centered on it.
userlocationlostfocus
Triggered when the user's location loses focus, such as when the map is panned away.
outofmaxbounds
Triggered when the user's location is outside the defined maximum bounds.