• Real-life examples
  • Reflect user location
Real-life examples

Reflect user location

Edit this page

This section shows an example of how to reflect the client location on the map using markers.

const map = new jsVectorMap({
  ...
  onLoaded(map) {
    const button = document.querySelector('#request-location')

    button.addEventListener('click', () => {
      navigator.geolocation.getCurrentPosition((position) => {
        map.instance.addMarkers({
          coords: [position.coords.latitude, position.coords.longitude]
        })
      })
    })
  }
  ...
})