This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| initLocationCompass(){ | |
| var _this = this; | |
| this.locationLoading().then(result => { | |
| console.info("Location: " + result); | |
| _this.loadCompass(result); | |
| _this.isLocationLoading = false; | |
| _this.isLocationError = false; | |
| }, error => { | |
| console.info("Location: error ->" + error); | |
| _this.isLocationLoading = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| loadCompass(coordinates = { | |
| latitude: 24.7136, | |
| longitude: 46.6753 | |
| }) { | |
| var _this = this; | |
| var qiblaDirection = parseFloat(this.qibla(coordinates)); | |
| console.log("compass: qiblaDirection: " + qiblaDirection); | |
| _this.needle_transform = "rotate(" + qiblaDirection + "deg)"; | |
| sensor.subscribeCompass({ | |
| success: function (ret) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| qibla(coordinates) { | |
| const makkah = { | |
| latitude: 21.42252, | |
| longitude: 39.82621 | |
| }; | |
| const term1 = Math.sin(this.degreesToRadians(makkah.longitude) - this.degreesToRadians(coordinates.longitude)); | |
| const term2 = Math.cos(this.degreesToRadians(coordinates.latitude)) * Math.tan(this.degreesToRadians(makkah.latitude)); | |
| const term3 = Math.sin(this.degreesToRadians(coordinates.latitude)) * Math.cos(this.degreesToRadians(makkah.longitude) - this.degreesToRadians(coordinates.longitude)); | |
| const angle = Math.atan2(term1, term2 - term3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "reqPermissions": [ | |
| { | |
| "name": "ohos.permission.INTERNET" | |
| }, | |
| { | |
| "name": "ohos.permission.LOCATION", | |
| "reason": "get Qibla direction", | |
| "usedScene": { | |
| "ability": [ | |
| "default" |
OlderNewer