function GpsInterface(map) { this.map = map; // map interface object this.elGpsInput = null; this._create = function() { this.elGpsInput = document.getElementById('actualgpsinput'); if (this.elGpsInput) this.elGpsInput.value = ''; this.attachEvents(); } this.updateGPS = function(latlng) { if (this.elGpsInput) { var df = latlng.lat; var c = 'N'; if (df < 0) { c = 'S'; df*= -1; } var d = Math.floor(df); var m = ((df - d) * 60).toFixed(3); if (m < 10) m = '0' + m; if (d < 10) d = '0' + d; var lat = c + d + '°' + m + '\''; df = latlng.lng; c = 'E'; if (df < 0) { c = 'W'; df*= -1; } d = Math.floor(df); m = ((df - d) * 60).toFixed(3); if (m < 10) m = '0' + m; if (d < 10) d = '0' + d; var lng = c + d + '°' + m + '\''; this.elGpsInput.value = lat + ' ' + lng; } } this.onClickMap = function(e) { this.updateGPS(this.map.getLatLngFromPixel(e.xy)); } this.attachEvents = function() { this.map.map.events.register('click', this, this.onClickMap); } this._create(); }