Cordova 为什么gps徽标没有';在状态栏中不显示?
我使用cordova-2.0.0并希望定义用户位置的协调。 此外,我只想得到gps坐标,而不是网络。 我怎么能做到? 为什么gps徽标不显示在状态栏中 My code index.html脚本:Cordova 为什么gps徽标没有';在状态栏中不显示?,cordova,gps,location,Cordova,Gps,Location,我使用cordova-2.0.0并希望定义用户位置的协调。 此外,我只想得到gps坐标,而不是网络。 我怎么能做到? 为什么gps徽标不显示在状态栏中 My code index.html脚本: function onSuccess(position) { var element = document.getElementById('geolocation'); element.innerHTML = 'Latitude: '+ position.coords.latit
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: '+ position.coords.latitude + '<br />' +
'Longitude: '+ position.coords.longitude + '<br />';
}
// onError Callback receives a PositionError object
//
function onError(error) {
var element = document.getElementById('geolocation');
element.innerHTML = 'code: ' + error.code + '\n' +
'message: ' + error.message + '\n';
}
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
成功时的功能(位置){
var element=document.getElementById('geolocation');
element.innerHTML='Latitude:'+position.coords.Latitude+''+ '经度:'+position.coords.Longitude+'
'; } //OneError回调接收PositionError对象 // 函数onError(错误){ var element=document.getElementById('geolocation'); element.innerHTML='code:'+error.code+'\n'+ '消息:'+error.message+'\n'; } //等待PhoneGap加载 文件。添加的监听器(“deviceready”,OnDeviceraddy,false); //PhoneGap已经准备好了 函数ondevicerady(){ navigator.geolocation.getCurrentPosition(onSuccess,onError); } 哦,这很容易。 选项-EnableHighAccurance:true。及其工作原理:) 但我如何使用CordovaAPI定义提供者呢?
例如:如果gps关闭,则应用程序会发出警报(“请,打开gps!”) 对于更新后的需求,您必须创建一个本地插件,该插件将检查GPS状态,并根据状态在html页面中显示警报
访问获取关于在android上创建本机插件的教程。如果在状态栏中看不到GPS徽标,那是因为GPS没有启动。可能一个JS文件没有加载 Cordova/phonegap不是本机代码,在watchPosition()函数上只有三个选项:maximumAge、timeout和EnableHighAccurance(使用GPS)。您只需将EnableHighAccurance设置为true,即可使用GPSProvider而不是NetworkBaseProvider。 也许您可以分析OneError函数中的错误消息,以查看在禁用GPS时是否发送了特殊消息 编辑:在我的测试中,没有特殊的消息提示,只有一条超时消息:“位置检索超时”。所以我想你不能检查科尔多瓦的GPS是开还是关 在我看来,Cordova/phonegap(以及所有的“跨平台”技术)并不是使用GPS和其他管理者(如TelephonyManager)开发应用程序的好选择 没有任何东西可以取代这方面的本机代码。 我还有一个问题:当我使用clearWatch()时,GPS不会停止: 这里是我的代码:
var currentTracking = false;
var idwatch = null;
function switchTracking() {
//when button is pressed to start GPS
if (!currentTracking) {
currentTracking = true;
document.getElementById('switchTracking').value = "Stop GPS"
tracking();
}
//when button is pressed to stop GPS
else {
navigator.geolocation.clearWatch(idwatch);
currentTracking = false;
document.getElementById('switchTracking').value = "Start GPS"
}
}
function tracking() {
if (currentTracking) {
idwatch = navigator.geolocation.watchPosition(onSuccess, onError,{ timeout: 5000, enableHighAccuracy: true });
}
else{
navigator.geolocation.clearWatch(idwatch);
}
}
function onSuccess(position) {
// alert("Gps");
var lat = document.getElementById('lat');
var long = document.getElementById('long');
lat.innerHTML = position.coords.latitude;
long.innerHTML = position.coords.longitude;
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
var currentTracking = false;
var idwatch = null;
function switchTracking() {
//when button is pressed to start GPS
if (!currentTracking) {
currentTracking = true;
document.getElementById('switchTracking').value = "Stop GPS"
tracking();
}
//when button is pressed to stop GPS
else {
navigator.geolocation.clearWatch(idwatch);
currentTracking = false;
document.getElementById('switchTracking').value = "Start GPS"
}
}
function tracking() {
if (currentTracking) {
idwatch = navigator.geolocation.watchPosition(onSuccess, onError,{ timeout: 5000, enableHighAccuracy: true });
}
else{
navigator.geolocation.clearWatch(idwatch);
}
}
function onSuccess(position) {
// alert("Gps");
var lat = document.getElementById('lat');
var long = document.getElementById('long');
lat.innerHTML = position.coords.latitude;
long.innerHTML = position.coords.longitude;
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}