function Get_LatLng_By_Digipin(vDigiPin) { vDigiPin = vDigiPin.replaceAll('-', ''); if (vDigiPin.length != 10) { return "Invalid DIGIPIN"; } var L1 = [ ['0', '2', '0', '0'], ['3', '4', '5', '6'], ['G', '8', '7', 'M'], ['J', '9', 'K', 'L'] ]; var L2 = [ ['J', 'G', '9', '8'], ['K', '3', '2', '7'], ['L', '4', '5', '6'], ['M', 'P', 'W', 'X'] ]; var MinLat = 1.50; var MaxLat = 39.00; var MinLng = 63.50; var MaxLng = 99.00; var LatDivBy = 4; var LngDivBy = 4; var LatDivVal = 0; var LngDivVal = 0; var ri, ci, f; var Lat1, Lat2, Lng1, Lng2; for (let Lvl = 0; Lvl < 10; Lvl++) { ri = -1; ci = -1; const digipinChar = vDigiPin.charAt(Lvl); LatDivVal = (MaxLat - MinLat) / LatDivBy; LngDivVal = (MaxLng - MinLng) / LngDivBy; f = 0; if (Lvl == 0) { for (let r = 0; r < LatDivBy; r++) { for (let c = 0; c < LngDivBy; c++) { if (L1[r][c] == digipinChar) { ri = r; ci = c; f = 1; break; } } } } else { for (let r = 0; r < LatDivBy; r++) { for (let c = 0; c < LngDivBy; c++) { if (L2[r][c] == digipinChar) { ri = r; ci = c; f = 1; break; } } } } if (f == 0) { return 'Invalid DIGIPIN'; } //console.log(ri + ' ' + ci); Lat1 = MaxLat - (LatDivVal * (ri + 1)); Lat2 = MaxLat - (LatDivVal * (ri)); Lng1 = MinLng + (LngDivVal * (ci)); Lng2 = MinLng + (LngDivVal * (ci + 1)); //console.log('Lat Range = ' + Lat1 + ' to ' + Lat2); //console.log('Lng Range = ' + Lng1 + ' to ' + Lng2); MinLat = Lat1; MaxLat = Lat2; MinLng = Lng1; MaxLng = Lng2; } cLat = (Lat2 + Lat1) / 2; cLng = (Lng2 + Lng1) / 2; return cLat + ', ' + cLng; }