stefanocudini / leaflet-compass

Leaflet plugin to show a rotating Compass!
https://opengeo.tech/maps/leaflet-compass/
MIT License
95 stars 23 forks source link

Android support #2

Closed stefanocudini closed 8 years ago

stefanocudini commented 10 years ago

Check compatibility on: https://github.com/stefanocudini/leaflet-compass/blob/master/src/leaflet-compass.js#L94

iOS: self._rotateCompass(e.webkitCompassHeading);

HTML5! self._rotateCompass(-e.alpha);

Reference: http://www.w3.org/TR/orientation-event/

thienbao92 commented 10 years ago

Hi stefanocudini,

Thank you for your wonderful contribution to the society. So what should I do just to change from self._rotateCompass(e.webkitCompassHeading); to self._rotateCompass(-e.alpha); in order to use the compass on android?

stefanocudini commented 10 years ago

I think this is the way, but unfortunately I do not have Android devices for testing. Maybe @sabas can help you

thienbao92 commented 10 years ago

I'm testing it. Hope it works, I will post my test later!!

stefanocudini commented 10 years ago

ok please patch and fork.. I need of this contribute!

thienbao92 commented 10 years ago

wow, it works smoothly. just have to to change from self._rotateCompass(e.webkitCompassHeading); to self._rotateCompass(-e.alpha); and then it works great. Thanks for your contribution

Here is demo : http://jsfiddle.net/thienbao92/e9avga6m/1/

stefanocudini commented 10 years ago

@mstn maybe you are interested

thienbao92 commented 10 years ago

Tested on Ionic/phonegap hybrid app builder on android, windows phone and iOS. Everything works great.

sabas commented 10 years ago

Perhaps could be integrated in the plugin? (if it's not working in ios it could be added some platform sniffing code)

stefanocudini commented 10 years ago

thanks @thienbao92 please can you send me a pull request including android support?

you can use the new Leaflet API L.Browser property for discern the behavior: http://leafletjs.com/reference.html#browser

tombtom commented 8 years ago

android browser work fine but new chrome no, it shows strange values on event deviceorientationabsolute or deviceorientation

stefanocudini commented 8 years ago

support Android Chrome device from version 1.0.0

stefanocudini commented 8 years ago

FYI @jpuerto @sabas @tombtom

jpuerto commented 8 years ago

Thanks for the update!