現在の場所の座標を取得して2つの変数に格納するために、サービスに次の関数を作成しました。
getCurrentLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
this.currLat = position.coords.latitude;
this.currLng = position.coords.longitude;
});
}
else {
alert("Geolocation is not supported by this browser.");
}
}
コンポーネントでそれらを使用するために、この関数を介して座標を返すにはどうすればよいですか?
継続的にポジションをリクエストしたい場合に備えて、
navigator.geolocation.watchPosition(res => ...