0
次のAngularJSクラスがTypeScriptで記述されています。私は基本的に2つのクラス変数に現在の位置の値を割り当てようとしていますが、このエラーが発生し続けます。現在の座標でのクラス変数の値の設定
Uncaught TypeError: Cannot set property 'longitude' of undefined at SearchCtrl.setLocations
ここで私はコントローラのコードを貼り付けます。
export class SearchCtrl implements ISearchCtrl {
longitude: number;
latitude: number;
constructor(public NgMap) {
navigator.geolocation.getCurrentPosition(this.setLocations);
}
setLocations(position): void {
this.longitude = position.coords.longitude;
this.latitude = position.coords.latitude;
}
}
おかげで、
ナノ
2つのクラス変数が変更されておらず、定義されていないようです。 – Nano
おそらく、position.coords.longitudeとposition.coords.latitudeは未定義です。デバッガを使用してください。 –
ポジションが無効になっています。ありがとう! – Nano