right. watchPosition acts like a listener on you geolocation infos, where getPosition just asks it one single time.
the thing is mobile devices do not update their location via browser as good as they do inside a native app, so waiting for watchPosition to ask dvice location 2 or 3 times might be a good idea. what i saw with you script is that you don't clear watchID from previous watchPosition so when you put a new watchPosition, it doesn't replace it but add a second listener to the previous one.... so it's loaded 2 times, then 3 times, then 4 times, ... and finally crash the browser (at least on my iphone). this is why i do clear it, then set it again. Remi Grumeau On 9 déc. 2011, at 01:34 PM, Thoern <[email protected]> wrote: > > Hi Remi, not sure how you mean 2,3,4.. watch position events as the > code only runs once at "initialise map" at startup so It should only > be one watchPosition event in watchID right? > > Isnt the point of using the watchPosistion that it follow the gps > point until you shut down the listner, in that example code it seems > it runs the watchposition as a function over and over again until the > checkbox is unchecked..? > Then one have to agree to let the website get you position all the > time.. > > function getLocation() > { > document.getElementById('output').innerHTML +='watching for > location...<br>'; > watchID = navigator.geolocation.watchPosition( > foundLocation, > errorLocation, > { > enableHighAccuracy: true, > maximumAge: 30000, > timeout: 27000 > } > ); > } > > function foundLocation(e) > { > var op = document.getElementById('output'); > > op.innerHTML += 'Accuracy: '+e.coords.accuracy+'<br>'; > op.innerHTML += 'Altitude: '+e.coords.altitude+'<br>'; > op.innerHTML += 'AltitudeAccuracy: '+e.coords.altitudeAccuracy > +'<br>'; > op.innerHTML += 'Heading: '+e.coords.heading+'<br>'; > op.innerHTML += 'Latitude: '+e.coords.latitude+'<br>'; > op.innerHTML += 'Longitude: '+e.coords.longitude+'<br>'; > op.innerHTML += 'Speed: '+e.coords.speed+'<br>'; > op.innerHTML += '--------------------<br>'; > > window.navigator.geolocation.clearWatch(watchID); > > if(document.getElementById('stopWatching').checked!=true) > getLocation(); > } > > -- > You received this message because you are subscribed to the Google Groups > "iPhoneWebDev" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/iphonewebdev?hl=en. > -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
