From the course: HTML5: Geolocation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Continuous tracking with watchPosition()

Continuous tracking with watchPosition() - HTML Tutorial

From the course: HTML5: Geolocation

Start my 1-month free trial

Continuous tracking with watchPosition()

Sometimes, especially in a mobile application, you may want to continuously update your location instead of just reading it once. This is accomplished by using watchPosition in place of the getCurrentPosition that we have been using to get the coordinates. Here we have 04-continuous-working.html. This is a working copy of 04-continuous-start.html, and I suggest you work with the working copy. It's pretty much where we left off in the last movie on error testing. So here we have our geo_error function right there, and you can see in the init function it's getting called back along with show_coords and the getCurrentPosition call, and there is HTML down at the bottom. So in order to make this continuously update the position, all we need to do is change this getCurrentPosition call to use watchPosition instead. When I save this, all this will do is instead of calling this show_coords function once, it will call it once, and then it will wait and see until the coordinates change and when…

Contents