Making the mobile application interactive
In the final example, called ch08_interact
, we extend the touch device part of our application and make it more interactive. We want to know our heading when we search for geocaches. Furthermore, it would be a nice feature if our application could give some extra information about a given cache that we could select manually.
Firstly, we extend our listener on the Geolocation
object's change
event with some necessary modifications. As we would like to track our position and heading, we modify our map's view on every change:
geoloc.on('change', function (evt) { […] map.getView().setCenter(this.getPosition()); if (this.getHeading()) { map.getView().setRotation(this.getHeading()); }
Tip
Just like an altitude value, heading is also a GPS-only feature. As receiving a heading is not guaranteed, you should always put the code responsible for rotating the map in an if
clause. You can provide the heading to the map's...