0

I am trying to find the bearing of the user in mapbox gl js and detect any change in it. In other words the direction which the user is facing in mapbox gl js and also if he chenges his direction. But I couldn't find much on this topic apart from this with some of its links not working and other being cordova specific solutions.

I am looking for a approach involving android webview and js for my solution. There are very few examples that I have been able to find regarding this.

Can anyone help me out here with anything on this please?

Edit

I am trying to find user's bearing, without using markers on the screen.

Community
  • 1
  • 1
abhishek ranjan
  • 612
  • 7
  • 23
  • Have you looked at the api documentation? https://docs.mapbox.com/mapbox-gl-js/api/ – Magnas May 21 '20 at 09:55
  • I have looked at the api but I am not sure which part there actually deals with the direction/bearing of the user and also helps in detecting a change in it. Can you please be a bit more specific. – abhishek ranjan May 21 '20 at 10:11
  • The bearing is a value in the options parameter of the map object. https://docs.mapbox.com/mapbox-gl-js/api/#map – Magnas May 21 '20 at 12:08
  • that was exactly what I started with. My complete problem is to find user's bearing , not map's bearing. – abhishek ranjan May 21 '20 at 12:16
  • Getting compass direction in a browser is pretty fiddly and doesn't work across all browsers and devices. See https://stackoverflow.com/questions/49696561/access-compass-data-in-mobile-web-html5 – Steve Bennett May 21 '20 at 12:37

1 Answers1

0

The Geolocation API is the standard web API for enabling users to provide their location to web applications. Mapbox GL JS's GeolocateControl is a wrapper around the browser's Geolocation API. This API does not have support for providing a user's bearing. Since there is no standard API across browsers for providing user bearing information, Mapbox GL JS does not natively expose a way to retrieve it.

If you are building for mobile, native SDKs such as the Mapbox Maps SDK for Android provide far more granularity for accessing current user location and bearing than web APIs.