Phonegap getCurrentPosition和watchPosition [英] Phonegap getCurrentPosition and watchPosition

查看:70
本文介绍了Phonegap getCurrentPosition和watchPosition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多关于此的文章. 我没有找到解决方案. 我需要的是更新我的当前职位.因此,如果我继续前进,我需要知道(每5秒钟)我的新职位.我知道watchPosition不适用于IOS.

I read so many post about this. I didn't find a solution. What i need is to update my current position. So if i will keep moving, i need to know (each 5 seconds) my new position. I understand that watchPosition doesn't work with IOS.

我从官方示例开始,我将其与setInterval混合

i'm starting from official example and i mix with setInterval

// Wait for PhoneGap to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);

        // PhoneGap is ready
        //
        function onDeviceReady() {
            setInterval(navigator.geolocation.getCurrentPosition(onSuccess, onError),5000);
        }

        // onSuccess Geolocation
        //
        function onSuccess(position) {
            alert("ENTRY");
            var element = document.getElementById('geolocation');
            element.innerHTML = 'Latitude: '           + position.coords.latitude              + '<br />' +
            'Longitude: '          + position.coords.longitude             + '<br />' +
            'Altitude: '           + position.coords.altitude              + '<br />' +
            'Accuracy: '           + position.coords.accuracy              + '<br />' +
            'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +
            'Heading: '            + position.coords.heading               + '<br />' +
            'Speed: '              + position.coords.speed                 + '<br />' +
            'Timestamp: '          + new Date(position.timestamp)          + '<br />';
        }

        // onError Callback receives a PositionError object
        //
        function onError(error) {
            alert('code: '    + error.code    + '\n' +
                  'message: ' + error.message + '\n');
        }

结果是我看到的所有信息只有一倍.然后停下来. 有人可以帮我吗?

The result is that i see just one times all information. And then stopping. Could someone help me?

推荐答案

我遇到了同样的问题,无论Web应用程序是否在IOS6上使用,或不在iOS 6上,都不会触发watchposition回调.看来IOS6打破了watchPosition.在启动时,它会发射一到两次,仅此而已.一旦失败,手表或getposition的进一步调用将不会触发成功或失败回调.

I have the same issue, watchposition call backs are not firing regardless of web app or not on IOS6. It appears IOS6 has broken the watchPosition. on start it fires once or twice and that's it. once failed out further calls of the watch or getposition do not fire success or failure callbacks.

我发现的解决方法是打开IOS 6中引入的maps应用程序,然后点击位置箭头以查找自己.尝试此操作后,回调大约每秒钟触发一次.

the work around I am finding is to open the maps app that was introduced in IOS 6 and tap the location arrow to find yourself. after trying this the callbacks fire as expected every second or so.

而且,只要您不在使用GPS接收器的地方,它就可以保持良好的运行状态.

Also, it appears to stay running well as long as you are outside where the GPS receiver is being used.

我作为bug提交给了苹果.

I submitted as bug to apple.

我能收集到的是地图正在执行初始化例程以打开API ...

All I can gather is maps is performing an initialize routine to open the API...

WatchPosition在IOS6之前一直运行良好.

WatchPosition has worked perfectly until IOS6.

这篇关于Phonegap getCurrentPosition和watchPosition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆