Skip to content

Instantly share code, notes, and snippets.

@Natgho
Last active January 22, 2021 12:15
Show Gist options
  • Save Natgho/10b193706d2b75b2a0af1ccabe8f81ee to your computer and use it in GitHub Desktop.
Save Natgho/10b193706d2b75b2a0af1ccabe8f81ee to your computer and use it in GitHub Desktop.
How to use Geolocation for Harmony OS
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