React-map-gl: Track User Location

Created on 21 Mar 2018  路  2Comments  路  Source: visgl/react-map-gl

Hi, is there a way to location the current coordinates of the user? Im referring to this example
https://www.mapbox.com/mapbox-gl-js/example/locate-user/

Thanks!

enhancement

Most helpful comment

@webdevsyd You can't use Mapbox's geolocate control directly, but it is not hard to make your own:

_locateUser() {
  // https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation
  navigator.geolocation.getCurrentPosition(position => {
    this.updateViewport({
      longitude: position.coords.longitude,
      latitude: position.coords.latitude
    });
  });
}

All 2 comments

@webdevsyd You can't use Mapbox's geolocate control directly, but it is not hard to make your own:

_locateUser() {
  // https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation
  navigator.geolocation.getCurrentPosition(position => {
    this.updateViewport({
      longitude: position.coords.longitude,
      latitude: position.coords.latitude
    });
  });
}

GeolocateControl is included since version 4.1.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abmai picture abmai  路  19Comments

xintongxia picture xintongxia  路  17Comments

paulosandinof picture paulosandinof  路  11Comments

vkammerer picture vkammerer  路  28Comments

tmhn picture tmhn  路  25Comments