Generating geocaches

In the next example, called ch08_points, we create some random geocaches based on the user's location. As server-side scripting and client-server connections are also out of the scope of this book, we make our application viable by adding random points within 500 meters of our position. Firstly, we create an empty layer for the points and initialize Geolocation:

var geoloc = new ol.Geolocation({
    projection: map.getView().getProjection(),
    tracking: true
});
var geoCaching = new ol.layer.Vector({
    source: new ol.source.Vector()
});
map.addLayer(geoCaching);

The ol.Geolocation constructor creates a simple wrapper object around the HTML5 Geolocation API. It is capable of everything the Geolocation API can do, and provides convenience ...

Get Mastering OpenLayers 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.