/** * A wrapper around HTML5 Geolocation with helper methods. * * @constructor */ function Geo() { "use strict"; /** * @type {Geolocation} */ var geo = navigator.geolocation; this.getGeo = function () { return geo; }; /** * * @param {MessageElement} area */ this.showLocation = function (area) { var that = this; geo.getCurrentPosition( function (position) { area.set(that.getPositionMessage(position)); }, function (error) { area.set(error); } ); }; /** * Build a HTML-formatted representation of a position information. * * @param {Position} position * @returns {string} */ this.getPositionMessage = function (position) { /** * @type {Coordinates} */ var coords = position.coords; var date = new Date(position.timestamp); var message = "

Position:

\n" + "\n"; return message; }; this.init = function () { geo = navigator.geolocation || false; }; this.init(); }