-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
291 lines (235 loc) · 8.74 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<link rel='stylesheet' href='https://unpkg.com/[email protected]/dist/leaflet.css'>
<style type="text/css" rel="stylesheet">
body {font-family: Verdana, Geneva, Arial, Helvetica}
.geocode {width: 20em; background-color: #FFFFCC;}
#map { width:calc(100% - 100px); height: 500px; }
.showing {visibility: show; height:500px;}
.hidden {visibility: hidden; height: 0px;}
.showmap {background-color: #00FF00; font-weight: 700; border-radius: 12px;}
.hidemap {background-color: #FF0000; font-weight: 700; color: #FFFFFF; border-radius: 12px;}
</style>
</head>
<body>
<script src='https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/Turf.js/5.0.4/turf.min.js'></script>
<h1>GS1 all-numeric geocodes</h1><h2>(to be used with new GS1 Application Identifier (4309) - ship-to / deliver-to geocode)</h2>
<p><a href="https://www.gs1.org/docs/barcodes/GSCN_21-318_GSCN_Geo-coordinates.pdf" target="_blank">GSCN 21-318</a> will introduce into the next edition of GS1 General Specifications a new GS1 Application Identifier (4309) for Ship-to / Deliver-to Geocode. The expected value is a 20-digit numeric string that encodes WGS84 latitude/longitude coordinates with a precision of around 1.1 centimetres. This is expected to be useful to support the delivery of parcels and logistic units that do not have a conventional postal address.</p>
<p><a href="https://en.wikipedia.org/wiki/Open_Location_Code" target="_blank">Open Location Code</a> uses 11 alphanumeric characters to identify a rectangle on the surface of the Earth, with a spatial precision around 3.5 metres</p>
By instead using 20 numeric digits it is possible to encode WGS84 latitude/longitude coordinates with a precision of around 1.1 centimetres<br/>
That's because 0.0000001 degrees corresponds to approximately 1.1cm on the surface of the Earth (2π * 6371,000m / 1E7 / 360)<br/>
20 digits require approximately the same number of bits to encode in a 2D barcode as 11 alphanumeric characters - but the spatial precision can be much higher than 3.5 metres afforded by Open Location Code.</p>
<p>Further technical details about this idea are provided in the <a href="https://github.com/gs1/geocode/blob/main/README.md" target="_blank">README page</a></p>
<div id="mapblock">
<div class="map_container" :class="showingInputMap ? 'showing' : 'hidden'">
<div id="map"></div>
</div>
<span style="left: 0%;"><input type="button" :value="showingInputMap ? 'Hide map' : 'Show map'" :class="showingInputMap ? 'hidemap' : 'showmap'" @click="toggleInputMap"></span>
</div>
<div id="app1">
<h2>Latitude, longitude to geocode</h2>
<table>
<tr><td><label for="inputLatitude">Latitude</label></td><td><input type="text" name="inputLatitude" v-model="inputLatitude"/></td></tr>
<tr><td><label for="inputLongitude">Longitude</label></td><td><input type="text" name="inputLongitude" v-model="inputLongitude"/></td></tr>
<tr><td><label for="outputGeocode">Numeric geocode</label></td><td><input type="text" class="geocode" name="outputGeocode" v-model="outputGeocode"/></td></tr>
</table>
<h3>Demo locations</h3>
<p><button @click="demo1">Reality Checkpoint, Cambridge, UK</button><br/>
<button @click="demo2">Bowali Visitor Centre, Kakadu National Park, Northern Territory, Australia</button><br/>
<button @click="demo3">Santa Claus Village in Rovaniemi, Finland</button><br/>
<button @click="demo4">Machu Picchu Antarctic Base</button><br/>
<button @click="clear">Clear demo values</button></p>
<h2>all-numeric geocode to latitude, longitude</h2>
<table>
<tr><td><label for="inputGeocode">Numeric geocode</label></td><td><input type="text" class="geocode" name="inputGeocode" v-model="inputGeocode"/><button @click="copyGeocode">Copy from above</button></td></tr>
<tr><td><label for="outputLatitude">Latitude</label></td><td><input type="text" name="outputLatitude" v-model="outputLatitude"/></td></tr>
<tr><td><label for="outputLongitude">Longitude</label></td><td><input type="text" name="outputLongitude" v-model="outputLongitude"/></td></tr>
</table>
<p v-if="openStreetMapURL"><a :href="openStreetMapURL" target="_blank">View on OpenStreetMap</p>
</div>
<script language="javascript">
let inputLatitude="";
let inputLongitude="";
let outputLatitude="";
let outputLongitude="";
let inputGeocode="";
function latlon2geocode(lat,lon) {
function pad10(str) {
return "0".repeat(10-str.length)+str;
}
let rv="";
if ((lat!=="") && (lon !=="")) {
let la=parseFloat(lat);
let lo=parseFloat(lon);
while (lo < 0) { lo+=360; }
while (lo > 360) { lo-=360; }
la+=90;
let lat7=Math.floor(la*1e7+0.499);
let lon7=Math.floor(lo*1e7+0.499);
recentreMap(lat,lon,18);
showPoint(lat,lon);
rv= pad10(lat7.toString())+pad10(lon7.toString());
}
return rv;
}
function geocode2latlon(geocode) {
let re=new RegExp('^[0-9]{20}$');
if ( (geocode !=="") && (re.test(geocode)) ) {
let clat=geocode.substr(0,10);
let clon=geocode.substr(10,10);
let lat=(parseInt(clat)-900000000)/1e7;
let lon=parseInt(clon)/1.00000000e7;
if (lon > 180) {
lon -=360;
}
recentreMap(lat,lon,18);
showPoint(lat,lon);
return {"lat":truncateAfter7Digits(lat.toString()),"lon":truncateAfter7Digits(lon.toString())};
} else {
return {}
}
}
function truncateAfter7Digits(str) {
let re=new RegExp('^([-]?\\d+\\.\\d{7})(\\d+)$');
if (re.test(str)) {
let arr = re.exec(str);
return arr[1];
} else {
return str;
}
}
function osmMapURL(lat,lon) {
if ((lat!=="")&&(lon!=="")){
return "https://www.openstreetmap.org/?mlat="+lat+"+&mlon="+lon+"#map=18/"+lat+"/"+lon;
} else {
return "";
}
}
function getComponent(obj,key) {
if (obj.hasOwnProperty(key)) {
return obj[key];
} else {
return "";
}
}
let mapblock=Vue.createApp({
data() {
return {
showingInputMap : false
}
},
methods : {
toggleInputMap: function() {
this.showingInputMap = !this.showingInputMap;
},
}
}).mount("#mapblock");
let app1=Vue.createApp({
data() {
return {
inputLatitude: inputLatitude,
inputLongitude: inputLongitude,
inputGeocode: inputGeocode,
showingInputMap : false
}
},
computed : {
outputGeocode : function() {
return latlon2geocode(this.inputLatitude,this.inputLongitude);
},
decodedObject : function() {
return geocode2latlon(this.inputGeocode);
},
openStreetMapURL: function() {
return osmMapURL(this.outputLatitude,this.outputLongitude);
},
outputLatitude: function() {
return getComponent(this.decodedObject,"lat");
},
outputLongitude: function() {
return getComponent(this.decodedObject,"lon");
}
},
methods : {
toggleInputMap: function() {
this.showingInputMap = !this.showingInputMap;
},
copyGeocode : function() {
this.inputGeocode = this.outputGeocode;
},
clear : function() {
this.inputLatitude="";
this.inputLongitude="";
},
demo1 : function() {
this.inputLatitude="52.2021950";
this.inputLongitude="0.1282028";
},
demo2 : function() {
this.inputLatitude="-12.67495";
this.inputLongitude="132.81715";
},
demo3 : function() {
this.inputLatitude="66.5435946";
this.inputLongitude="25.8470550";
},
demo4 : function() {
this.inputLatitude="-62.0914152";
this.inputLongitude="-58.4702029";
}
}
}).mount("#app1");
//var map = L.map('map').setView([52.20220197878701, 0.1281988620758057], 18);
var zoom=1;
var map = L.map('map').setView([0.00, 0.00], 1);
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '<br/>© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
function to7decimalplaces(val) {
if (val > 0) {
return Math.floor(1e7*val+0.4999999999)/1e7
} else {
return Math.ceil(1e7*val-0.4999999999)/1e7
}
}
let mapMarkers=[];
function recentreMap(lat,lon,zoom) {
map.setView(new L.LatLng(lat, lon), zoom);
}
function clearMapMarkers() {
for(let i = 0; i < mapMarkers.length; i++){
map.removeLayer(mapMarkers[i]);
}
return mapMarkers.length;
}
function showPoint(lat,lon) {
clearMapMarkers();
c = new L.circle([lat,lon], {radius: 0, color: '#FF0000'});
c.addTo(map);
mapMarkers.push(c);
c = new L.circle([lat,lon], {radius: 5, color: '#000000', fillColor: '#000000'});
c.addTo(map);
mapMarkers.push(c);
}
map.on('click', function(e) {
zoom+=2;
if (zoom > 18) {
zoom=18;
}
console.log("Map clicked");
let lat=to7decimalplaces(e.latlng.lat);
let lon=to7decimalplaces(e.latlng.lng);
while (lon> 180) { lon-=360 }
while (lon< -180) { lon+=360 }
app1.inputLatitude=lat
app1.inputLongitude=lon;
recentreMap(lat,lon,zoom);
showPoint(lat,lon);
});
</script>
</body>
</html>