maplibre-gl-js icon indicating copy to clipboard operation
maplibre-gl-js copied to clipboard

add support for “direction arrow” feature. i.e. add support for showUserHeading in GeolocateControl

Open deveshbhatta opened this issue 1 year ago • 8 comments

User Story

This section should have a one-sentence sentence user story, such as:

As a developer I can show end user Heading direction , so that end user can navigate properly.

See also: https://docs.mapbox.com/mapbox-gl-js/example/locate-user/

Rationale

  • Why is this feature needed? - to show direction user heading to
  • What are some example use cases? Position in respect to pinned location.
  • Can it be done today? Is there a workaround? No

Impact

  • Multiple developer has asked for the “direction arrow” feature. This is very important for developer who is using JS (or react JS) for their app.

deveshbhatta avatar Sep 15 '23 17:09 deveshbhatta

From my experience, in the web browser, especially iOS, this functionality is almost impossible to get right. I have that in an app I'm maintaining, and I needed to use the native compass heading (that is not available in the browser) due to all kinds of permission requests on iOS. So generally speaking, this would make sense, but in practice I'm not sure how doable it is... Feel free to open a PR.

HarelM avatar Sep 15 '23 20:09 HarelM

If using The Geolocation API is enough for you guys, I am willing to work on this.

IhsenBen avatar Nov 15 '23 11:11 IhsenBen

From my experience, in the web browser, especially iOS, this functionality is almost impossible to get right.

@HarelM it's interesting to know that on iOS it's almost impossible to do, but what about Android ? For my use case, supporting this feature on Android would enable the feature for 75 % of my users (France).

laem avatar Jul 09 '24 11:07 laem

Interesting : the compass works perfectly for me in both Chrome and Firefox on my Android device https://idzgd.csb.app. (It appears blocked on Bromite though).

Here is the corresponding sandbox https://codesandbox.io/s/idzgd.

It has an active isIOS branch.

laem avatar Jul 09 '24 11:07 laem

If this is working as expected for you and you would like to open a PR to add this functionality, feel free to do so. It might be that browser nowadays are supporting this better than before...

HarelM avatar Jul 10 '24 14:07 HarelM

My tests on social media tell me it's working for 90% of users :)

Edit : I had more than 20 answers, not working for only 1 user.

Checkout this react implementation cartes.app/nord.

Not sure how to implement this in maplibre, should it be a plugin or an extension of GeolocateController triggered by a param ?

laem avatar Jul 10 '24 17:07 laem

I think a property in the options and some rendering on the map would be sufficient. I still hope to split the geolocation control into a state management, HW related code and UI related code, if you are up to it that would be amazing.

HarelM avatar Jul 10 '24 19:07 HarelM

May be useful to integrate magnetic declination. Declination can be significant, e.g., 23 degrees for NZ. This might help? https://www.npmjs.com/package/geomag

antonmarsden avatar Jul 13 '24 09:07 antonmarsden

Sorry, I don't have time to contribute to MapLibre, but you can try my integration on https://cartes.app. The code is here.

Summary : it's just a marker rotated by the degree value returned by the useCompass react hook. Works well for me (except for a bug on subsequent clics on the geoloc button).

image

laem avatar Jul 28 '24 15:07 laem