Phonegap getCurrentPosition and watchPosition

I read so many posts about this. I did not find a solution. I need to update the current position. Therefore, if I continue to move, I need to know (every 5 seconds) my new position. I understand that watchPosition does not work with iOS.

I start with an 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'); } 

As a result, I see only once all the information. And then he stopped. Can someone help me?

0
source share
3 answers

watchPosition works fine for me on iOS using the latest Cordoba (Phonegap). Maybe you should give this method one more try, since it looks like what you want.

+1
source

I have the same problem, watchposition callbacks do not work regardless of web application or not on iOS6. IOS6 seems to have broken watchPosition. at startup it fires once or twice and that it is. after further watch calls or getposition fail, callbacks or failures do not work.

the job i find is to open the maps app that was introduced in iOS 6 and click the location arrow to find myself. upon waking up, this causes callbacks to be expected every second or so.

In addition, it works well while you are outside where the GPS receiver is used.

I posted as an error in apple.

All I can collect is that the cards perform the initialization procedure to open the API ...

WatchPosition works fine before iOS6.

+1
source

I believe the problem is that you are passing a setInterval value instead of a function. You should have something more:

 setInterval( function(){ navigator.geolocation.getCurrentPosition(onSuccess, onError); }, 5000); 

As you do now, getCurrentPosition is run once, it returns the position of the setInterval ... function, and then the position value is called every 5 seconds (and not the getCurrentPosition function), which is pretty pointless.

0
source

Source: https://habr.com/ru/post/1436043/


All Articles