我正在使用https://github.com/mauron85/cordova-plugin-background-geolocation。它在前台提供位置详细信息,并在关闭应用程序时提供调试消息,但不会将位置详细信息同时更新到服务器的前台和后台。
提前致谢
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 10,
distanceFilter: 10,
debug: false,
stopOnTerminate: false,
startForeground: true,
notificationTitle: 'location tracking',
notificationText: 'Active',
interval: 60000,
url: localStorage.getItem('api_base_url')+'user/currentlocation',
syncUrl:localStorage.getItem('api_base_url')+'user/currentlocation',
httpHeaders: {
'Content-Type': 'application/json'
},
postTemplate: {
lat: '@latitude',
lon: '@longitude',
user_id: '1',
currentDate: '12-12-2019',
address: 'test',
}
};
this.backgroundGeolocation.configure(config)
.then(() => {
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location).subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
});
});
this.backgroundGeolocation.start();
请记住,当postTemplate为jsonObject和jsonArray的数组数组时,所有位置(甚至单个位置)都将作为对象数组发送!
在服务器端,我将JSON对象更改为对象数组。
例如,
{
"user_id": "1",
"lon": "13.2",
"lat": "82.3"
}
我将上面的JSON对象更改为以下
[{
"user_id": "1",
"lon": "13.2",
"lat": "82.3"
}]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句