1var UserLocation = { 2 3 // Set variables 4 locationType: '', // Set available location type: [ by-browser | by-server ] 5 coords: '', // Stored coords will be here 6 7 // Setup 8 accuracy: 5, // This will be added to the database to prevent knowing the EXACT location. 9 timeout: 5000, // Timeout for getting current position 10 maximumAge: 0, // Maximum age of the position 11 enableHighAccuracy: true, // Set whether to retrieve a more accurate location of the browser 12 13 // Initial boot function 14 init: function () { 15 16 // Determine location type 17 UserLocation.testBrowser(); 18 19 // Fetch location on init 20 UserLocation.fetchLocation(); 21 22 }, 23 24 /* 25 * Store coords and eventually modify them 26 */ 27 setCoords: function (coords) { 28 29 UserLocation.coords = coords; 30 31 }, 32 33 /* 34 * Get stored coords 35 */ 36 getCoords: function () { 37 38 return UserLocation.coords; 39 40 }, 41 42 // Test browser for location functionality 43 testBrowser: function () { 44 45 // If browser hasn't been tested yet 46 if (UserLocation.locationType === '') { 47 48 // Check for geolocation options 49 if (navigator.geolocation) { 50 51 UserLocation.locationType = 'by-browser'; 52 53 } else { 54 55 UserLocation.locationType = 'by-server'; 56 57 } 58 59 } 60 61 }, 62 63 fetchLocation: function () { 64 65 if (UserLocation.locationType == 'by-browser') { 66 67 // Retrieve by GPS location 68 UserLocation.askClientForLocation(); 69 70 } else if (UserLocation.locationType == 'by-server') { 71 72 // Not implemented yet. 73 74 } 75 76 }, 77 78 askClientForLocation: function () { 79 80 navigator.geolocation.getCurrentPosition(UserLocation.storeLocation, UserLocation.errorLocation, { 81 timeout: UserLocation.timeout, 82 maximumAge: UserLocation.maximumAge, 83 enableHighAccuracy: UserLocation.enableHighAccuracy 84 }); 85 86 }, 87 88 storeLocation: function (position) { 89 90 UserLocation.setCoords(position.coords);
91 92 UserLocation.getCoords(); 93 94 $.post( 95 '/', 96 { 97 jsonData: UserLocation.prepareData(UserLocation.getCoords()) 98 } 99 ); 100 101 }, 102 103 // Prepare data to post to server 104 prepareData: function (data) { 105 106 var postData = { 107 108 lat: data.latitude, 109 lon: data.longitude, 110 securityToken: securityToken 111 112 } 113 114 return JSON.stringify(postData); 115 116 }, 117 118 errorLocation: function (error) { 119 120 // Warning to console 121 console.warn('ERROR ' + error.code + ': ' + error.message); 122 123 /* 124 // Fallback for location type 125 UserLocation.locationType = 'by-server'; 126 127 // Fetch location again but by server now 128 UserLocation.fetchLocation(); 129 */ 130 131 } 132 133} 134 135$(function () { 136 137 UserLocation.init(); 138 139});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.