我想把GPS音轨保存在一个用钛金制作的应用程序中(目前是安卓系统),但我不知道怎么做。
我的目标是每隔5秒跟踪用户的位置,并将其保存在手机中(我认为,保存在JSON文件中将是更好的解决方案)。我希望它既能在后台工作,又能在手机没有网络的情况下工作。一旦手机有了网络,我就想把文件同步到服务器上。
有可能吗?
目前,我只将一个基本函数(来自appcelerator文档)和一个setInterval ...但位置总是一样的,即使我在搬家。
下面是我的代码:
function save(){
setInterval(function(){
if (Ti.Geolocation.locationServicesEnabled) {
Titanium.Geolocation.purpose = 'Get Current Location';
Titanium.Geolocation.distanceFilter = 1 ;
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
Ti.API.error('Error: ' + e.error);
} else {
Ti.API.info(e.coords.altitude);
Ti.API.info(e.coords.heading);
Ti.API.info(e.coords.latitude);
Ti.API.info(e.coords.longitude);
Ti.API.info(e.coords.speed);
alert('LAT : '+e.coords.latitude+' LONG : '+e.coords.longitude+' SPEED : '+e.coords.speed+' ALT : '+e.coords.altitude);
}
});
} else {
alert('Please enable location services');
}
}, 5000);
}
save_button.addEventListener('click', function(){
save();
});我真的不知道该怎么做。如果有人能帮我... :)
非常感谢:)
发布于 2016-05-20 05:39:05
如果你想追踪gps的位置,最好设置一个eventListener Ti.Geolocation.addEventListener('location', function(e){ //same response returned by Titanium.Geolocation.getCurrentPosition() });。
监听器的灵敏度可以像这样调整
Ti.Geolocation.Android.manualMode = true;
function androidProviderConfig(provider) {
var providerGps = Ti.Geolocation.Android.createLocationProvider({
name : provider,
minUpdateDistance : 100,
//minUpdateTime: 60
});
Ti.Geolocation.Android.addLocationProvider(providerGps);
var gpsRule = Ti.Geolocation.Android.createLocationRule({
provider : provider,
accuracy : 50,
maxAge : 20 * 60 * 1000, // 1h
minAge : 10 * 1000 // 10 seconde
});
Ti.Geolocation.Android.addLocationRule(gpsRule);
}
//androidProviderConfig(Ti.Geolocation.PROVIDER_NETWORK);
//or
androidProviderConfig(Ti.Geolocation.PROVIDER_GPS);
Ti.Geolocation.addEventListener('location', function(e){/*your callback*/});https://stackoverflow.com/questions/37171640
复制相似问题