setUserLocation はマーカーのスタイル定義です。位置の更新は setUserLocationData で行います。navigator.geolocation.watchPosition) と組み合わせてください。setTrackingMode で設定します。import * as GIA from '@ntj/gaia';
const userLocation = new GIA.object.UserLocation({
info: new GIA.value.GLMarkerIconInfo({
icon: USER_LOCATION_ICON,
size: new GIA.value.Size(30, 30),
gravity: 'center',
}),
});
// マーカースタイルを設定
map.setUserLocation(userLocation);
map.setTrackingMode('follow');
// GPS位置を取得して更新
navigator.geolocation.watchPosition((pos) => {
const latLng = new GIA.value.LatLng(pos.coords.latitude, pos.coords.longitude);
const heading = pos.coords.heading ?? 0;
map.setUserLocationData(new GIA.value.UserLocationData(latLng, heading), true);
});
import * as GIA from '@ntj/gaia';
const intervalMs = 1000;
map.setUserLocationDataInterval(intervalMs * 0.001); // 秒単位
const point = new GIA.value.UserLocationData(
new GIA.value.LatLng(35.6812, 139.7671),
90,
);
map.setUserLocationData(point, true);
import * as GIA from '@ntj/gaia';
const userLocation = new GIA.object.UserLocation({
info: new GIA.value.GLMarkerIconInfo({ icon: USER_LOCATION_ICON }),
});
map.setUserLocation(userLocation);
userLocation.setProjectionMode('perspective');
自位置マーカーの表示と位置情報の更新を行う — 詳細な使用例
UserLocationオブジェクトで自位置マーカーのアイコン・スタイルを設定し、UserLocationDataで実際の緯度経度・精度・向きを更新します。 GPS連動させる場合はsetUserLocationDataIntervalで更新間隔も設定してください。setUserLocation(ul)setUserLocationData(data)getUserLocationData()setUserLocationDataInterval(sec)