本文整理匯總了TypeScript中ionic-native.Geolocation.watchPosition方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Geolocation.watchPosition方法的具體用法?TypeScript Geolocation.watchPosition怎麽用?TypeScript Geolocation.watchPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ionic-native.Geolocation
的用法示例。
在下文中一共展示了Geolocation.watchPosition方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: startTracking
startTracking() {
console.log(":startTracking: ", BackgroundGeolocation);
let options = {
frequency: 3000,
enableHighAccuracy: true
};
this.watch = Geolocation.watchPosition(options);
this.watch.subscribe((data) => {
alert("latitude: "+data.coords.latitude);
alert("longitude: "+data.coords.longitude);
console.log("latitude: "+data.coords.latitude);
console.log("longitude: "+data.coords.longitude);
this.notifyLocation(data.coords);
});
let backgroundOptions = {
desiredAccuracy: 10,
stationaryRadius: 10,
distanceFilter: 30
};
this.backGeolocation.configure((location) => {
this.notifyLocation(location);
}, (err) => {
console.log(err);
}, backgroundOptions);
this.backGeolocation.start();
return this.position;
}
示例2: startWatch
startWatch() {
this.subscription = Geolocation.watchPosition(this.options).subscribe(position => {
this.record=true;
console.log(position);
this.geo = position;
});
}
示例3: watchPosition
/**
* Watch the position
*/
public watchPosition():void{
this.isWatching = true;
this.subscription = Geolocation.watchPosition().subscribe((position) => {
this.mapsService.getAddress(position.coords.latitude, position.coords.longitude).then((data) => {
this.address = data[0].formatted_address;
});
this.mapsService.moveToPosition(this.map, position.coords.latitude, position.coords.longitude);
});;
}
示例4:
Geolocation.getCurrentPosition().then(pos => {
this.watchGeoID = Geolocation.watchPosition();
this.watchGeoID.subscribe(
(data:Geoposition) => {
// data can be a set of coordinates, or an error (if an error occurred).
// data.coords.latitude
// data.coords.longitude
this.onGeoSuccess(data)
},
(err:PositionError) => this.onGeoError('startGeolocation Error: location not available')
);
}).catch(err=> {this.onGeoError('startGeolocation Error: location not available')});
示例5: gpsToggleBrowser
gpsToggleBrowser(value) {
if (value) {
let options = { maximumAge:100, timeout:Infinity, enableHighAccuracy:false};
this.watcher = Geolocation.watchPosition(options).subscribe((data) => {
var obj: any = new Object();
obj.accuracy = data.coords.accuracy;
obj.altitude = data.coords.altitude;
obj.altitudeAccuracy = data.coords.altitudeAccuracy;
obj.heading = data.coords.heading;
obj.latitude = data.coords.latitude;
obj.longitude = data.coords.longitude;
obj.speed = data.coords.speed;
let postData: any = JSON.stringify(obj);
this.userData.setGpsData(postData);
this.latitude = data.coords.latitude;
this.longitude = data.coords.longitude;
this.app.getComponent('tab2').tabBadge++;
})
} else {
try {
this.watcher.unsubscribe();
this.watcher = null;
} catch (e) {
alert('Error unsubscribe: ' + e.statusText);
console.log(e);
}
}
}