Last active
January 22, 2021 12:15
-
-
Save Natgho/10b193706d2b75b2a0af1ccabe8f81ee to your computer and use it in GitHub Desktop.
How to use Geolocation for Harmony OS
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
import geolocation from '@system.geolocation'; | |
import battery from '@system.battery'; | |
export default { | |
data: { | |
index: 0, | |
latlon: "", | |
accuracy: 0, | |
battery: 0, | |
}, | |
updateData() { | |
var anchor = this; | |
geolocation.getLocation({ | |
success: function (data) { | |
anchor.latlon = "\n" + data.latitude + "\n" + data.longitude; | |
anchor.accuracy = data.accuracy; | |
} | |
}) | |
battery.getStatus({ | |
success: function (data) { | |
anchor.battery = data.level; | |
} | |
}) | |
}, | |
onInit() { | |
this.updateData(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment