Polyline::decode PHP Метод

decode() закрытый публичный статический Метод

Reverse Google Polyline algorithm on encoded string.
final public static decode ( string $string ) : array
$string string Encoded string to extract points from.
Результат array points
    public static final function decode($string)
    {
        $points = array();
        $index = $i = 0;
        $previous = array(0, 0);
        while ($i < strlen($string)) {
            $shift = $result = 0x0;
            do {
                $bit = ord(substr($string, $i++)) - 63;
                $result |= ($bit & 0x1f) << $shift;
                $shift += 5;
            } while ($bit >= 0x20);
            $diff = $result & 1 ? ~($result >> 1) : $result >> 1;
            $number = $previous[$index % 2] + $diff;
            $previous[$index % 2] = $number;
            $index++;
            $points[] = $number * 1 / pow(10, static::$precision);
        }
        return $points;
    }

Usage Example

 /**
  * Test rounding issues report by issue #10
  *
  * @return NULL
  */
 public function testRounding()
 {
     $originalPoints = array(48.000006, 2.000004, 48.00001, 2.0);
     $encoded = Polyline::encode($originalPoints);
     $this->assertEquals('a_~cH_seK??', $encoded);
     $decodedPoints = Polyline::decode($encoded);
     $this->assertTrue($decodedPoints[0] === $decodedPoints[2]);
     $this->assertTrue($decodedPoints[1] === $decodedPoints[3]);
 }
All Usage Examples Of Polyline::decode