要发送到服务器ionic 2+的后台地理位置信息>> [

问题描述 投票:1回答:1
我想从后台地理位置插件向我的服务器发送不同的配置设置。但是,我不确定如何使它正常工作。我已经准备好了位置服务器。只是不确定如何发送该数据。我想将启动跟踪配置放在发布请求中。但是不确定如何检索该信息以及我下面的代码是否正确。谢谢!

location.ts

import { Injectable, NgZone } from '@angular/core'; import { BackgroundGeolocation, BackgroundGeolocationConfig } from '@ionic-native/background-geolocation'; import { Geolocation, Geoposition } from '@ionic-native/geolocation'; import 'rxjs/add/operator/filter'; @Injectable() export class LocationTracker { public watch: any; public lat: number = 0; public lng: number = 0; public bearing: number = 0; public speed: number = 0; constructor(public zone: NgZone, public backgroundGeolocation: BackgroundGeolocation, public geolocation: Geolocation) { } startTracking() { let config = { desiredAccuracy: 0, stationaryRadius: 20, distanceFilter: 10, debug: true, interval: 2000, bearing: 10, speed: 0, }; this.backgroundGeolocation.configure(config).subscribe((location) => { console.log('BackgroundGeolocation: ' + location.latitude + ',' + location.longitude); // Run update inside of Angular's zone this.zone.run(() => { this.lat = location.latitude; this.lng = location.longitude; }); }, (err) => { console.log(err); }); // Turn ON the background-geolocation system. this.backgroundGeolocation.start(); // Foreground Tracking let options = { frequency: 60000, enableHighAccuracy: true }; this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => { console.log(position); // Run update inside of Angular's zone this.zone.run(() => { this.lat = position.coords.latitude; this.lng = position.coords.longitude; }); }); } stopTracking() { console.log('stopTracking'); this.backgroundGeolocation.finish(); this.watch.unsubscribe(); } }

我想从后台地理位置插件向我的服务器发送不同的配置设置。但是,我不确定如何使它正常工作。我已经准备好了位置服务器。 ...
cordova ionic-framework ionic2 ionic3
1个回答
0
投票
您的代码适用于离子4。不确定是否适用于离子2
© www.soinside.com 2019 - 2024. All rights reserved.