2
現在の位置を表示する簡単なPOCを開発中です。 プログラムはgeolocation.watchLocationから情報を受信しますが、モニタリングの停止ボタンを押すまで、位置はバインドされずに画面に表示されます。ログが正しくあなたが()=>
代わりのfunction()
を使用する場合は、あなたが_self
ハックを必要としない座標にAngular2データバインディングを持つNativeScriptがジオロケーションで動作しない
JS: Start Monitoring ...
JS: Location: 49.6411839:6.0040451
JS: Stop Monitoring ...
import {Component} from "@angular/core";
import {Router} from "@angular/router";
import geolocation = require("nativescript-geolocation");
@Component({
selector: "TrackingPageSelector",
template:`
<StackLayout>
<Button [text]="watchId==0 ? 'Start Monitoring' : 'Stop Monitoring'" (tap)="buttonStartStopTap()"></Button>
<Label class="labelValue" [text]="latitude"> </Label>
<Label class="labelValue" [text]="longitude"> </Label>
</StackLayout>`
})
export class TrackingPageComponent {
latitude: number = 0;
longitude: number = 0;
watchId: number = 0;
constructor(private router: Router) {}
ngOnInit() {
if (!geolocation.isEnabled()) geolocation.enableLocationRequest();
}
public buttonStartStopTap() {
if (this.watchId != 0) {
console.log('Stop Monitoring ...');
geolocation.clearWatch(this.watchId);
this.watchId = 0;
} else {
console.log('Start Monitoring ...');
let _self = this;
this.watchId = geolocation.watchLocation(
function (loc) {
if (loc) {
_self.latitude = loc.latitude;
_self.longitude = loc.longitude;
console.log(`Location: ${_self.latitude}:${_self.longitude}`);
}
},
function(e){
this.errorMsg = e.message;
},
{desiredAccuracy: 3, updateDistance: 10, minimumUpdateTime: 1000 * 3}); // Should update every X seconds
}
}
}
実際に提供されたソリューションは機能します。私は、detectChanges提案を実装しました。ご協力ありがとうございました! –
これがあなたの質問に答えるならば、問題が解決されたことを明らかにするために、アップダウン投票ボタンの下にある白いチェックマークを使って自分の答えを受け入れることによって、ありがとう! –