1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- function Geo() {
- "use strict";
-
- var geo = navigator.geolocation;
- this.getGeo = function () {
- return geo;
- };
-
- this.showLocation = function (area) {
- var that = this;
- geo.getCurrentPosition(
- function (position) {
- area.set(that.getPositionMessage(position));
- },
- function (error) {
- area.set(error);
- }
- );
- };
-
- this.getPositionMessage = function (position) {
-
- var coords = position.coords;
- var date = new Date(position.timestamp);
- var message = "<p>Position: </p>\n" +
- "<ul>\n" +
- " <li>Timestamp: " + position.timestamp + " = " + date.toLocaleString() + "</li>\n" +
- " <li>Accuracy: " + coords.accuracy + " meters</li>\n" +
- " <li>Latitude: " + coords.latitude + "</li>" +
- " <li>Longitude: " + coords.longitude + "</li>" +
- " <li>Altitude: " + (coords.altitude ? coords.altitude : "unknown") + "</li>" +
- " <li>Altitude Accuracy: " + (coords.altitudeAccuracy ? coords.altitudeAccuracy : 0) + "</li>" +
- " <li>Heading: " + (coords.heading ? coords.heading : "unknown") + "</li>\n" +
- " <li>Speed: " + (coords.speed ? coords.speed : "unknown") + "</li>\n" +
- " </ul>\n";
- return message;
- };
- this.init = function () {
- geo = navigator.geolocation || false;
- };
- this.init();
- }
|