1
I’m trying to pass a function written in javasript to php,but I think I was wrong in translating some command and I can’t find the error. Javascript function:
<script>
function dec(string)
{// retorna a matris pura, descompactada
var myArray = [];
var str, str2, arr, arr2, lat, lng, f;
var strings = string.split(" ");
for(var i=0; i<strings.length; i++)
{
str = strings[i];
str2 = '';
arr = [];
arr2 = [];
for (var j=0; j<str.length; j++)
{
switch (str.charAt(j))
{
case 'A': str2 += ',0'; break;
case 'B': str2 += ',1'; break;
case 'C': str2 += ',-1'; break;
case 'D': str2 += ',2'; break;
case 'E': str2 += ',-2'; break;
case 'F': str2 += ',3'; break;
case 'G': str2 += ',-3'; break;
case 'H': str2 += ',4'; break;
case 'I': str2 += ',-4'; break;
case 'J': str2 += ',5'; break;
case 'K': str2 += ',-5'; break;
case 'L': str2 += ',6'; break;
case 'M': str2 += ',-6'; break;
case 'N': str2 += ',7'; break;
case 'O': str2 += ',-7'; break;
case 'P': str2 += ',8'; break;
case 'Q': str2 += ',-8'; break;
case 'R': str2 += ',9'; break;
case 'S': str2 += ',-9'; break;
default: str2 += str.charAt(j); break;
}
}
arr = str2.split(",");
f = arr.shift();
lng = parseInt(arr[0])/f;
lat = parseInt(arr[1])/f;
arr2.push([lat, lng]);
for (var j=2; j<arr.length; j+=2)
{
lng += parseInt(arr[j])/f;
lat += parseInt(arr[j+1])/f;
arr2.push([lat, lng]);
}
myArray.push(arr2);
}
return myArray;
}
dec("1000I6575E3374BCBAACBABABABABBABBAABBBABBAABBABBDABAABBBABBAABBAABBABAABBBABBAABBBABBBBAABBAACBABCBABAABBABCBAACBCACBABAACBABAACBAAAACCAACCCACBCACACCACCCCCAACCCCCCACAACACACACACACACACACACCCACAACAACCCCCCCCCCACCACCCACCACCACACACBAACACACCAACACCAACACBAACACACCACCCACAACCACAACAACAACCACAACCACAACACBAACAAACACACCAACBCAAACACACACACACCAACACCAACACBAACACBAACBAACACACACACACCACAACACACACACCAACACCAACBAACACCAACCAACACACCCACACBAACBAACACACBAACACBAACBAACACBCBCBCACBAACACACBAACACACACACACACACACACACACACBCACACACACACCEACCEACACBAACACBAACBAACACAAACACBABCBAACBAABBBBABBBABABABABAABBABBBAABBBBBABBAABBBBBBBBABBBAABBBABBABAABBABABAABBAABBABBABBBBAABBBBAABBABABBABBABABBBABBBABAABBABABABBBABABABAABBABABABABABABABBBABABABCBABABAACBABBBABADABABABABABCBABABABCBABCBABCBABAACBABABAACBABABABABABABBACBABABBBABABABABAABBABABABABBBABABAABBAACBABABABAABBABAABCBABBABABAACBCBAABCAABBABAABABABBABAABBABABCBABABABAACBABAAAABBABBACBAACBABAABCAABBAABBABAABBABAACACBABAACCCCAACBABAACACBCBAABABBAACACBACCCABCBAACCACAACACCAACACBAACBABAABBAACBAACBAABABBAABABBABCBABAABBAABBAABBABABABAACBABABAABABBAABCAABABABBAABAAAABAACBAABAAABABBAABBAACACBAACACBAACACBAACBAACCAACBAACACACBAACBAACACBAACBCACBAACBAACACBAACBAACACACBAACACBAACBAACACBAACBAACACACACCAACACACACACCACACACBCACACAACCACCACBAACCAACCACACACACAACCACAACCAACACACCACACCAAACBABAACCAACCAACCACAACCAACCAACCAACCAACCBCACAACAAACBAACACACACACACBAACBCACBABAACBCACBAACACACCCCAECCACACAAEBCBAACACBACCACBAACAAACACBAACBABCBABAACBABABCBABABABAAAACACECCCACAAACCABCCCBAACBABAACACBABABAACACCACCCACACCCAACACBABCBAACACBAACACBCACBAACACBAACCAABCAABCAACCAACCAACCCACACACCAACACACBAACACCAACCACACACACACCCCCAABCACACACAACCCCCCAACAAACACBABCBAACBCACACACCAACCCCAACACACCAACCAACCAACCACCCACACACAACACCAACACBCACACACACCAACCACACCCCCACAACACACCAACACCACAACCACACACAACACACCACACAABABABABCACBABCAABCACACBCCCAACACACBAACCAACCACACACBCCCACACACACCCCCACACACACBCACACAABCACAABCACACACAACCACAABCACAABCAABCACACAABCAACCBACCACACACACACAABABCAABABCAABABCAABAAABAAABCAABABABABCAABCCABCACBCACACACAABCACAACCACACAACCAABCACCCACAABCAACCACAABCACACAACCACACCCACACAABCACBCAABCAABCAABABCAABCAABCACACACBABCACBCAABCACACACACACACACACACAACCBCACACACAABCACBCAABCACAABCACBCAABCAABCAABCACACACACAACCAACCAACCCACCACCCACACBCACBCBCACBCAABCACBCAABCAABCACAABCACBCBCACACAABCACAACACACACACACCAACACACAECCACAEAECEACACACCCAEACACBAACBAACACCCACACCACAACCAACACBCACAEACBACCACACCAACACCACCCAACCAACCACAACCACAACCACAACCAACCACACACAACCACAACCAACCACACACAACCACCCAACCACACAACCACAABCAABCAABCCEAACCCCAACCACBCAABCAACACCCACACACACACACACCAACACCACAACCAACACACACACBAACACCCCAACCAACCAACBAACACACCCACCCCCACBABABAACACBAACACACACBABABCACACBAACBAACBCBBBAACACACACBAABBCACBABABABAACBAACACBAACCAACCAACCAACCACAACCACACCCACACACCCCCCCCCCCCCCCCCAACCAACCACAACCAECCAECCAEACCCACCCABKBAAEBEACDSAEAEBEBCBEDELOBEFGDGJKACBCBCACACAGAC2ACACACACAKACACACACCCAEAECAACCCCCCAACCAACEECCCCCCACACACACACCEAGAGBEBOBEBCDCDADEDCDCDEDCACAEACACACACACACBCACACACACACACCAACACACACAECAACACACACACBCACBCCCBEBCCCBCACACACBAACACACACBAACHBEECCCAACACBAACACACACDAACBAACACCAACACBCACACACACCACAACBCBCACCACACAACACCAACCAAAEACAACACACBCACACBABABCDABBDAACBAACCCACCAACBCBECCBCCAACACCACAACCAACDEBAACBAACACACACCAACAAACCACAACBABACCBCACCCCACAACAACCACACACCAABABCACBCAACCACACCACCAACCACACACACAACCACACAACCCABCAACAACAACCAACCACAACCACAACBAACACACBCACBAACACACACACBAACBAACBABAACCAACCACACACCACCCCACBCAACCAACACCAACCACACAACCACACACCCACCCAAACAABCBABCBABCACAABCBABCACBCACAABABCBCBCACACACACACACCCACACACACACACACACBCACAABCAABCBABABCAABCACACCACCACCCACBCACACCACCAACCACCCAACCAACCACACCCACCCAABCACACACACCACCACCCACAACCAACCACACACACBCAABABCACACCCACACACACCCACACACACACAABCACBCAABCACACACACACACAACACCACACACACACAACBAACCACAAACACACACCCAACACCAACCCCCACCACACCACACCACACACAABCAACCAACCCCACACAABABCACAABABCAABBAABBABBBAABBABAABBAABABABBBABBBCBBAABBBABBAABBABAABABBAABBAABABABBAABBAABCAABABBABAABBAABBAABABABABCACAACCAABCAABCBCBCAABCAABCAABBAABABABCBCACBCACCCAABCACACAABCBCBABCAABABBAABCBABBBABCACACACACBCACAABCAABCACAABBAABCAABCAABCBCACBCACAACCAACCACACACBCBABCAABCACAABCACACACACACCCACBABABABABCBABABABABABCBABCBABABABABCBABABBACBCAABBAABABCAABABBAABCAABBACBBAABAAABABBAABBAABABBAABBAABABBBABBAABABABBAABCAABBACBABCAAACAABABABABAABABCBBACBABAACBAACACACACBAACBABAABBABABCBABADABABCBABAABBABADADABABBBABAABBJADABAFANAPAB0ABCAABCAABCBABCABBABCAABBAABABABABCAABABBABABABAACBABCBABBACBABBBABAACBAABBABABAABABBAABABABABABABABCACCABCAABBABAABBAABABABABABABCACBCAABCAABCAABCAABCAABCACAABCAABCACAABCACAABCACBCAABCACAABCACACACACAABCACAABCACACACACACACACACAABCACACAABCAABABABBAABAAABBAABCAABBAAABAABBAABBABAABABABABBAABBAABBBBAABABBABAABBAABCAAAABAABAAABBABCACAABBACBABAAABCBABABABBBABABBABBDBDABBBABABBABBBBBABBABBBABABAABBBBAABBDABBDABABABABCBCACBCACCCACAABCAABCAABCACAABCCACCAABCAABCAABCACAABCACBCBCAABCBBBABCACAABCACACBCAABABABABCBABCAABABCBABBAABDBBAABABBAABBBABBBCAABBAABABABCAABBAABABCAABABABABABAAABBAABABABBAABAAABCAABAAABCAABCACACACBCACACBCAABBABABAABBAABABCAABCBABABCBABCAABCAABBACBBAABABBAABABABABABBBABABBAABBAABABBAABABBAABABABABABABBAABABAAABABABABBAABABABABBAABABABABAAABCAABABBABBBBBAABABABBAABBBBABAABABBABABABAABBAABBABAABAAABBAABABABBAABBABAABBABAABBABAABBAABBAABABBAABBAABBAABBAABBBBAABBAABABABBAABBAABBABAABBAABBAACBAABBABAABABABABBBBAABBBCACAABABCACAABCACACBCACAABCAABABCBABCAACCAACCAACCAACCACACACCCACACACACACAACCCACCACAEBCCACCACACACACACAACCACAACCACACBCACCCACACAABCACACAACACCCCACACACCCACACAAAABCBABABAAABABCAABBAABCAABABABBAABABBBCAABBAABABBBABBAABABCAABCAABABABBABABABABBAABABABABAACBBBABAABABBABAABBAABABBABBBCBBBAABABBAABBABABCBAABBBBBABBABABABABBBABAABBAABABABABBABABDBAAABAACBABAABABABBAABABBABBABABBAABBAABABBAABABCAABABBAABCAABCBABABABBAABABABABABABABCAABBAABABABABABABDBBDBBBABABABABABABAABBAABABBDCACAACCACACAABCAABABABCACAABEACAABABAAABCACAABABCBAAABCACBABCAABABBAABBAABABBAABBAABBABABAABABABBAABAAABCAABCACAABCACACACACAABCACAABCAABABABCAABABCAABCBABABABABADABABABCAABCACAABCAABCAABABCBABABBAABABABBAABBABAABABBBABBABAABCACAACCACAACCAACACCCCCACCACACACACAABCAACCAACCACACACAABCAABCAABCACAABCAAACACAACCACAACCCACBAACCAACACACCACAACCACBBBABCAABCBCBCBCBABCAABABABABABABABCAABCAABABCAABABABABABABABCAABBBABCAABCACAABABABABABCAABCAABCAABCAABABABCACACBCAABCAABCAABCBABABABABBAABBABAABABABABABCAABCAABABCACAABCAABCBABBAABBAABCAABCBBAABBAABBAABBAACBAABBAABBABAAABAABBCBABABAABBABABCBABAABBAABAABAABBABABAABCAABBABAACBAACBAACBAACACCAACCAACBAACBAABBAACBABACBABBAABBABABABAACBAACAAAABABAACAAACBABAACBABBBABAABABABCAABABBABAABBABABCBABABACBBBBABABABABAAAABABAAABBAABCAABBAABABABABBAACBAABABBABAABBAABBAACBABCBAABBAACBAABBABCBABABAACACBAACBABABAABBAAABAACBAABBCABBABAAABABAACBBBABABABABBBAACBAACACBAACBAACBAACBABABAACBABABABABAACBAACBABCACACACACACACBAACBCBCBABABABABABBACBAACACBCACACACACACACBAAABAACBABABABABCABBABAACACACACACACACBABABABABABABBBABCBCBCBCBABAABBBABABABABABABBABBBAABBABABAABBABBACBADEBCBABABABABAACBAACBCBCACBABCBABABCBCACBCACBAACBABABBBABABBBABABABABBBABABABABADBBABCBABAACBABABBBAABABBABABDBBBABADABAABBAABABCBCBABBABABAACBABADABABABAABBACBCBABABABABBABAABBACDABABBBBBABBBABBAABBAABBBBAABBABABBBABBBAABABABCBCAABABABBABBBABAABBABBBABABABBBBBBABBABABAABBAABBAABBAABBABAABABBBBABABABABA");
</script>
Function in PHP:
Descompacta('1000I6575E3374BCBAACBABABABABBABBAABBBABBAABBABBDABAABBBABBAABBAABBABAABBBABBAABBBABBBBAABBAACBABCBABAABBABCBAACBCACBABAACBABAACBAAAACCAACCCACBCACACCACCCCCAACCCCCCACAACACACACACACACACACACCCACAACAACCCCCCCCCCACCACCCACCACCACACACBAACACACCAACACCAACACBAACACACCACCCACAACCACAACAACAACCACAACCACAACACBAACAAACACACCAACBCAAACACACACACACCAACACCAACACBAACACBAACBAACACACACACACCACAACACACACACCAACACCAACBAACACCAACCAACACACCCACACBAACBAACACACBAACACBAACBAACACBCBCBCACBAACACACBAACACACACACACACACACACACACACBCACACACACACCEACCEACACBAACACBAACBAACACAAACACBABCBAACBAABBBBABBBABABABABAABBABBBAABBBBBABBAABBBBBBBBABBBAABBBABBABAABBABABAABBAABBABBABBBBAABBBBAABBABABBABBABABBBABBBABAABBABABABBBABABABAABBABABABABABABABBBABABABCBABABAACBABBBABADABABABABABCBABABABCBABCBABCBABAACBABABAACBABABABABABABBACBABABBBABABABABAABBABABABABBBABABAABBAACBABABABAABBABAABCBABBABABAACBCBAABCAABBABAABABABBABAABBABABCBABABABAACBABAAAABBABBACBAACBABAABCAABBAABBABAABBABAACACBABAACCCCAACBABAACACBCBAABABBAACACBACCCABCBAACCACAACACCAACACBAACBABAABBAACBAACBAABABBAABABBABCBABAABBAABBAABBABABABAACBABABAABABBAABCAABABABBAABAAAABAACBAABAAABABBAABBAACACBAACACBAACACBAACBAACCAACBAACACACBAACBAACACBAACBCACBAACBAACACBAACBAACACACBAACACBAACBAACACBAACBAACACACACCAACACACACACCACACACBCACACAACCACCACBAACCAACCACACACACAACCACAACCAACACACCACACCAAACBABAACCAACCAACCACAACCAACCAACCAACCAACCBCACAACAAACBAACACACACACACBAACBCACBABAACBCACBAACACACCCCAECCACACAAEBCBAACACBACCACBAACAAACACBAACBABCBABAACBABABCBABABABAAAACACECCCACAAACCABCCCBAACBABAACACBABABAACACCACCCACACCCAACACBABCBAACACBAACACBCACBAACACBAACCAABCAABCAACCAACCAACCCACACACCAACACACBAACACCAACCACACACACACCCCCAABCACACACAACCCCCCAACAAACACBABCBAACBCACACACCAACCCCAACACACCAACCAACCAACCACCCACACACAACACCAACACBCACACACACCAACCACACCCCCACAACACACCAACACCACAACCACACACAACACACCACACAABABABABCACBABCAABCACACBCCCAACACACBAACCAACCACACACBCCCACACACACCCCCACACACACBCACACAABCACAABCACACACAACCACAABCACAABCAABCACACAABCAACCBACCACACACACACAABABCAABABCAABABCAABAAABAAABCAABABABABCAABCCABCACBCACACACAABCACAACCACACAACCAABCACCCACAABCAACCACAABCACACAACCACACCCACACAABCACBCAABCAABCAABABCAABCAABCACACACBABCACBCAABCACACACACACACACACACAACCBCACACACAABCACBCAABCACAABCACBCAABCAABCAABCACACACACAACCAACCAACCCACCACCCACACBCACBCBCACBCAABCACBCAABCAABCACAABCACBCBCACACAABCACAACACACACACACCAACACACAECCACAEAECEACACACCCAEACACBAACBAACACCCACACCACAACCAACACBCACAEACBACCACACCAACACCACCCAACCAACCACAACCACAACCACAACCAACCACACACAACCACAACCAACCACACACAACCACCCAACCACACAACCACAABCAABCAABCCEAACCCCAACCACBCAABCAACACCCACACACACACACACCAACACCACAACCAACACACACACBAACACCCCAACCAACCAACBAACACACCCACCCCCACBABABAACACBAACACACACBABABCACACBAACBAACBCBBBAACACACACBAABBCACBABABABAACBAACACBAACCAACCAACCAACCACAACCACACCCACACACCCCCCCCCCCCCCCCCAACCAACCACAACCAECCAECCAEACCCACCCABKBAAEBEACDSAEAEBEBCBEDELOBEFGDGJKACBCBCACACAGAC2ACACACACAKACACACACCCAEAECAACCCCCCAACCAACEECCCCCCACACACACACCEAGAGBEBOBEBCDCDADEDCDCDEDCACAEACACACACACACBCACACACACACACCAACACACACAECAACACACACACBCACBCCCBEBCCCBCACACACBAACACACACBAACHBEECCCAACACBAACACACACDAACBAACACCAACACBCACACACACCACAACBCBCACCACACAACACCAACCAAAEACAACACACBCACACBABABCDABBDAACBAACCCACCAACBCBECCBCCAACACCACAACCAACDEBAACBAACACACACCAACAAACCACAACBABACCBCACCCCACAACAACCACACACCAABABCACBCAACCACACCACCAACCACACACACAACCACACAACCCABCAACAACAACCAACCACAACCACAACBAACACACBCACBAACACACACACBAACBAACBABAACCAACCACACACCACCCCACBCAACCAACACCAACCACACAACCACACACCCACCCAAACAABCBABCBABCACAABCBABCACBCACAABABCBCBCACACACACACACCCACACACACACACACACBCACAABCAABCBABABCAABCACACCACCACCCACBCACACCACCAACCACCCAACCAACCACACCCACCCAABCACACACACCACCACCCACAACCAACCACACACACBCAABABCACACCCACACACACCCACACACACACAABCACBCAABCACACACACACACAACACCACACACACACAACBAACCACAAACACACACCCAACACCAACCCCCACCACACCACACCACACACAABCAACCAACCCCACACAABABCACAABABCAABBAABBABBBAABBABAABBAABABABBBABBBCBBAABBBABBAABBABAABABBAABBAABABABBAABBAABCAABABBABAABBAABBAABABABABCACAACCAABCAABCBCBCAABCAABCAABBAABABABCBCACBCACCCAABCACACAABCBCBABCAABABBAABCBABBBABCACACACACBCACAABCAABCACAABBAABCAABCAABCBCACBCACAACCAACCACACACBCBABCAABCACAABCACACACACACCCACBABABABABCBABABABABABCBABCBABABABABCBABABBACBCAABBAABABCAABABBAABCAABBACBBAABAAABABBAABBAABABBAABBAABABBBABBAABABABBAABCAABBACBABCAAACAABABABABAABABCBBACBABAACBAACACACACBAACBABAABBABABCBABADABABCBABAABBABADADABABBBABAABBJADABAFANAPAB0ABCAABCAABCBABCABBABCAABBAABABABABCAABABBABABABAACBABCBABBACBABBBABAACBAABBABABAABABBAABABABABABABABCACCABCAABBABAABBAABABABABABABCACBCAABCAABCAABCAABCAABCACAABCAABCACAABCACAABCACBCAABCACAABCACACACACAABCACAABCACACACACACACACACAABCACACAABCAABABABBAABAAABBAABCAABBAAABAABBAABBABAABABABABBAABBAABBBBAABABBABAABBAABCAAAABAABAAABBABCACAABBACBABAAABCBABABABBBABABBABBDBDABBBABABBABBBBBABBABBBABABAABBBBAABBDABBDABABABABCBCACBCACCCACAABCAABCAABCACAABCCACCAABCAABCAABCACAABCACBCBCAABCBBBABCACAABCACACBCAABABABABCBABCAABABCBABBAABDBBAABABBAABBBABBBCAABBAABABABCAABBAABABCAABABABABABAAABBAABABABBAABAAABCAABAAABCAABCACACACBCACACBCAABBABABAABBAABABCAABCBABABCBABCAABCAABBACBBAABABBAABABABABABBBABABBAABBAABABBAABABBAABABABABABABBAABABAAABABABABBAABABABABBAABABABABAAABCAABABBABBBBBAABABABBAABBBBABAABABBABABABAABBAABBABAABAAABBAABABABBAABBABAABBABAABBABAABBAABBAABABBAABBAABBAABBAABBBBAABBAABABABBAABBAABBABAABBAABBAACBAABBABAABABABABBBBAABBBCACAABABCACAABCACACBCACAABCAABABCBABCAACCAACCAACCAACCACACACCCACACACACACAACCCACCACAEBCCACCACACACACACAACCACAACCACACBCACCCACACAABCACACAACACCCCACACACCCACACAAAABCBABABAAABABCAABBAABCAABABABBAABABBBCAABBAABABBBABBAABABCAABCAABABABBABABABABBAABABABABAACBBBABAABABBABAABBAABABBABBBCBBBAABABBAABBABABCBAABBBBBABBABABABABBBABAABBAABABABABBABABDBAAABAACBABAABABABBAABABBABBABABBAABBAABABBAABABCAABABBAABCAABCBABABABBAABABABABABABABCAABBAABABABABABABDBBDBBBABABABABABABAABBAABABBDCACAACCACACAABCAABABABCACAABEACAABABAAABCACAABABCBAAABCACBABCAABABBAABBAABABBAABBAABBABABAABABABBAABAAABCAABCACAABCACACACACAABCACAABCAABABABCAABABCAABCBABABABABADABABABCAABCACAABCAABCAABABCBABABBAABABABBAABBABAABABBBABBABAABCACAACCACAACCAACACCCCCACCACACACACAABCAACCAACCACACACAABCAABCAABCACAABCAAACACAACCACAACCCACBAACCAACACACCACAACCACBBBABCAABCBCBCBCBABCAABABABABABABABCAABCAABABCAABABABABABABABCAABBBABCAABCACAABABABABABCAABCAABCAABCAABABABCACACBCAABCAABCAABCBABABABABBAABBABAABABABABABCAABCAABABCACAABCAABCBABBAABBAABCAABCBBAABBAABBAABBAACBAABBAABBABAAABAABBCBABABAABBABABCBABAABBAABAABAABBABABAABCAABBABAACBAACBAACBAACACCAACCAACBAACBAABBAACBABACBABBAABBABABABAACBAACAAAABABAACAAACBABAACBABBBABAABABABCAABABBABAABBABABCBABABACBBBBABABABABAAAABABAAABBAABCAABBAABABABABBAACBAABABBABAABBAABBAACBABCBAABBAACBAABBABCBABABAACACBAACBABABAABBAAABAACBAABBCABBABAAABABAACBBBABABABABBBAACBAACACBAACBAACBAACBABABAACBABABABABAACBAACBABCACACACACACACBAACBCBCBABABABABABBACBAACACBCACACACACACACBAAABAACBABABABABCABBABAACACACACACACACBABABABABABABBBABCBCBCBCBABAABBBABABABABABABBABBBAABBABABAABBABBACBADEBCBABABABABAACBAACBCBCACBABCBABABCBCACBCACBAACBABABBBABABBBABABABABBBABABABABADBBABCBABAACBABABBBAABABBABABDBBBABADABAABBAABABCBCBABBABABAACBABADABABABAABBACBCBABABABABBABAABBACDABABBBBBABBBABBAABBAABBBBAABBABABBBABBBAABABABCBCAABABABBABBBABAABBABBBABABABBBBBBABBABABAABBAABBAABBAABBABAABABBBBABABABABA');
function Descompacta($string){
$myArray = [];
$str;
$str2;
$arr;
$arr2;
$lat;
$lng;
$f;
$strings = split(" ",$string);
for($i=0; $i<count($strings); $i++)
{
$str = $strings[$i];
$str2 = '';
$arr = [];
$arr2 = [];
for ($j=0; $j<strlen($str); $j++)
{
switch (substr($str,$j))
{
case 'A': $str2 += ',0'; break;
case 'B': $str2 += ',1'; break;
case 'C': $str2 += ',-1'; break;
case 'D': $str2 += ',2'; break;
case 'E': $str2 += ',-2'; break;
case 'F': $str2 += ',3'; break;
case 'G': $str2 += ',-3'; break;
case 'H': $str2 += ',4'; break;
case 'I': $str2 += ',-4'; break;
case 'J': $str2 += ',5'; break;
case 'K': $str2 += ',-5'; break;
case 'L': $str2 += ',6'; break;
case 'M': $str2 += ',-6'; break;
case 'N': $str2 += ',7'; break;
case 'O': $str2 += ',-7'; break;
case 'P': $str2 += ',8'; break;
case 'Q': $str2 += ',-8'; break;
case 'R': $str2 += ',9'; break;
case 'S': $str2 += ',-9'; break;
default: $str2 += substr($str,$j); break;
}
}
$arr = split(",",$str2);
$f = array_shift($arr);
$lng = $arr[0]/$f;
$lat = $arr[1]/$f;
array_push($arr2,[$lat, $lng]);
for ($j=2; $j<count($arr); $j+=2)
{
$lng += $arr[$j]/$f;
$lat += $arr[$j+1]/$f;
array_push($arr2,[$lat, $lng]);
}
array_push($myArray,$arr2);
}
}
The mistakes start here:
$arr = split(",",$str2);
Has anyone figured out where the mistake is?
,got it,but I think the error is when I quit switchcase because if I give print_r on $str2,it comes out as "INF"
– Rodolfo Oliveira
That’s not what you meant in the question, I haven’t been analyzing everything. But in your
switch()
you’re concatenating with+=
but in PHP you have to use.=
:)– Zuul
@Rodolfooliveira I was reviewing the function, solved more problems I found and set an example in Ideone. Read the answer so you know where I found problems and why they happened.
– Zuul
It seems that you are right, but I noticed that in the examples the
intval
(to be equivalent toparseInt
), no? I haven’t tested the code and I really don’t know how it works, but I believe this is part of the important.– Guilherme Nascimento
@Guilhermenascimento Thanks, I had not seen this detail. I did not understand yet if it is required or if it already came from the original in JS, but it is there :)
– Zuul