Ios Cordova背景地理定位插件
我正在为ios应用程序使用这个cordova插件,但遇到了一些问题。如果有人能帮忙,我将不胜感激 下面是我从插件示例本身使用的示例代码 问题是,当检测到位置更改时,回调函数(callbackFn)似乎没有被调用,但我确实在Iphone上收到通知,我看到其中一个通知是由于未完成的bg任务被强制终止。不知道这到底是什么意思Ios Cordova背景地理定位插件,ios,cordova,Ios,Cordova,我正在为ios应用程序使用这个cordova插件,但遇到了一些问题。如果有人能帮忙,我将不胜感激 下面是我从插件示例本身使用的示例代码 问题是,当检测到位置更改时,回调函数(callbackFn)似乎没有被调用,但我确实在Iphone上收到通知,我看到其中一个通知是由于未完成的bg任务被强制终止。不知道这到底是什么意思 var app = { // Application Constructor initialize: function() { this.bind
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
if (window.plugins.backgroundGeoLocation) {
app.configureBackgroundGeoLocation();
}
},
// Update DOM on a Received Event
receivedEvent: function(id) {
window.cache.clear( function(){console.log("cache cleared");}, function(){console.log("cache could not be cleared");} );
require(['http://localhost:8080/sdm/app_resources/app_product_HY6I1FJ5KGRD/resources/js/main.js']);
},
configureBackgroundGeoLocation: function() {
// Your app must execute AT LEAST ONE call for the current position via standard Cordova geolocation,
// in order to prompt the user for Location permission.
window.navigator.geolocation.getCurrentPosition(function(location) {
console.log('Location from Phonegap');
});
var bgGeo = window.plugins.backgroundGeoLocation;
/** This would be your own callback for Ajax-requests after POSTing background geolocation to your server.*/
var yourAjaxCallback = function(response) {
bgGeo.finish();
};
/**This callback will be executed every time a geolocation is recorded in the background.*/
var callbackFn = function(location) {
console.log('[js] BackgroundGeoLocation callback: ' + location.latitudue + ',' + location.longitude);
// Do your HTTP request here to POST location to your server.
deviceId = 'I2FKRKXX8SQ0';
trackingToken = 'SomeSecurityToken';
jsonData={location:{longitude:location.longitude,latitude:location.latitude}};
var encodedToken = Base64.encode('tracker' + ':' + trackingToken);
var http = new XMLHttpRequest();
var url = "http://localhost:8080/sdm/v1/KC/host/device/"+deviceId;
var params = JSON.stringify(jsonData);
http.open("PUT", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/json");
http.setRequestHeader("accept", "json");
http.setRequestHeader("Authorization", "Basic "+encodedToken);
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
/* http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}*/
http.send(params);
yourAjaxCallback.call(this);
};
var failureFn = function(error) {
console.log('BackgroundGeoLocation error');
}
// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
activityType: 'AutomotiveNavigation',
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
bgGeo.start();
// If you wish to turn OFF background-tracking, call the #stop method.
// bgGeo.stop()
}
var-app={
//应用程序构造函数
初始化:函数(){
这是bindEvents();
},
bindEvents:function(){
文件.addEventListener('devicerady',this.ondevicerady,false);
},
ondevicerady:function(){
app.receivedEvent(“DeviceRady”);
if(window.plugins.backgroundGeoLocation){
app.configureBackgroundGeoLocation();
}
},
//在接收到的事件上更新DOM
receivedEvent:函数(id){
window.cache.clear(function(){console.log(“缓存已清除”);},function(){console.log(“缓存无法清除”);});
需要(['http://localhost:8080/sdm/app_resources/app_product_HY6I1FJ5KGRD/resources/js/main.js']);
},
configureBackgroundGeoLocation:函数(){
//您的应用程序必须通过标准Cordova地理位置对当前位置执行至少一次呼叫,
//以提示用户获取位置权限。
window.navigator.geolocation.getCurrentPosition(函数(位置){
log('Phonegap中的位置');
});
var bgGeo=window.plugins.backgroundGeoLocation;
/**这将是在将后台地理位置发布到服务器之后,您自己对Ajax请求的回调*/
var yourAjaxCallback=函数(响应){
bgGeo.finish();
};
/**每次在后台记录地理位置时,都将执行此回调*/
var callbackFn=函数(位置){
log('[js]BackgroundGeoLocation回调:'+location.latitude+','+location.longitude');
//在此处执行HTTP请求以将位置发布到服务器。
deviceId='I2FKRKXX8SQ0';
trackingToken='SomeSecurityToken';
jsonData={位置:{经度:位置。经度,纬度:位置。纬度};
var encodedToken=Base64.encode('tracker'+':'+trackingToken);
var http=new XMLHttpRequest();
变量url=”http://localhost:8080/sdm/v1/KC/host/device/“+设备ID;
var params=JSON.stringify(jsonData);
http.open(“PUT”,url,true);
//随请求一起发送正确的标头信息
setRequestHeader(“内容类型”、“应用程序/json”);
setRequestHeader(“接受”、“json”);
http.setRequestHeader(“授权”、“基本”+encodedToken);
setRequestHeader(“内容长度”,参数长度);
setRequestHeader(“连接”,“关闭”);
/*http.onreadystatechange=function(){//在状态更改时调用函数。
如果(http.readyState==4&&http.status==200){
警报(http.responseText);
}
}*/
http.send(params);
yourAjaxCallback.call(this);
};
var failureFn=功能(错误){
log('backgroundgeolocationerror');
}
//背景地理定位是高度可配置的。
bgGeo.configure(callbackFn、failureFn、{
期望准确度:10,
静止半径:20,
距离过滤器:30,
activityType:“自动导航”,
debug:true,//您还必须在开始时添加回调函数和失败函数。我也遇到了同样的问题。
例如,配置:bgGeo.configure(callbackFn、failureFn。。。
bgGeo.start();
必须更改为bgGeo.start(callbackn,failureFn);
您还必须在start中添加回调函数和失败函数。我也遇到了同样的问题。
例如,配置:bgGeo.configure(callbackFn、failureFn。。。
bgGeo.start();
必须更改为bgGeo.start(callbackn,failureFn);
您还必须在start中添加回调函数和失败函数。我也遇到了同样的问题。
例如,配置:bgGeo.configure(callbackFn、failureFn。。。
bgGeo.start();
必须更改为bgGeo.start(callbackn,failureFn);
您还必须在start中添加回调函数和失败函数。我也遇到了同样的问题。
例如,配置:bgGeo.configure(callbackFn、failureFn。。。
bgGeo.start();
必须更改为bgGeo.start(callbackn,failureFn);
检查您是否正在使用android。除非您有高级版本的Christrocracy插件,否则它将不会执行您的回调函数。您必须为android设备指定url
检查您是否正在使用android。除非您有高级版本的Christrocracy插件,否则它不会执行您的回调函数。您必须为android设备指定要发送的位置的url
检查您是否正在使用android。除非您有高级版本的Christrocracy插件,否则它不会执行您的回调函数。您必须为android设备指定要发送的位置的url
检查您是否正在使用android。除非您有高级版本的Christrocracy插件,否则它不会执行您的回调函数。您必须为android设备指定要发送的位置的url
如果您愿意,可以尝试我的后台插件,