1function mapboxCalculateRoute(qry, color) { 2 if(typeof color !== 'undefined') color = "#ffc107"; 3 $.get('https://api.mapbox.com/matching/v5/mapbox/driving/' + qry + '?geometries=geojson&steps=true&access_token='+token, 4 function( data ) { 5 if(data.matchings.length > 0){ 6 var coords = data.matchings[0].geometry.coordinates; 7 let coords_line = []; 8 for(let i=0; i<coords.length; i++){ 9 coords_line.push([coords[i][1],coords[i][0]]); 10 } 11 polylineLayer = L.polyline(coords_line, {color: color}).addTo(myMap) 12 13 } 14 }); 15} 16 17function averageGeolocation(coords) { 18 if (coords == null) { 19 return coords; 20 }else if(coords.length === 1) { 21 return coords[0]; 22 } 23 24 var x = 0.0; 25 var y = 0.0; 26 var z = 0.0; 27 28 // for (var coord of coords) { 29 for (var i=0; i<coords.length ; i++) { 30 var coord = coords[i]; 31 var latitude = coord.lat * Math.PI / 180; 32 var longitude = coord.lng * Math.PI / 180; 33 34 x += Math.cos(latitude) * Math.cos(longitude); 35 y += Math.cos(latitude) * Math.sin(longitude); 36 z += Math.sin(latitude); 37 } 38 39 var total = coords.length; 40 41 x = x / total; 42 y = y / total; 43 z = z / total; 44 45 var centralLongitude = Math.atan2(y, x); 46 var centralSquareRoot = Math.sqrt(x * x + y * y); 47 var centralLatitude = Math.atan2(z, centralSquareRoot); 48 49 return { 50 Latitude: centralLatitude * 180 / Math.PI, 51 Longitude: centralLongitude * 180 / Math.PI 52 }; 53}
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.