public function encode($lat, $long)
        {
            //how many bits does latitude need?
            $plat = $this->precision($lat);
            $latbits = 1;
            $err = 45;

            while($err > $plat) {
                $latbits++;
                $err /= 2;
            }

            //how many bits does longitude need?
            $plong = $this->precision($long);
            $longbits = 1;
            $err = 90;

            while($err > $plong) {
                $longbits++;
                $err/=2;
            }

            //bit counts need to be equal
            $bits = max($latbits, $longbits);

            //as the hash create bits in groups of 5, lets not
            //waste any bits - lets bulk it up to a multiple of 5
            //and favour the longitude for any odd bits
            $longbits = $bits;
            $latbits  = $bits;
            $addlong  = 1;

            while (($longbits + $latbits) % 5 != 0) {
                $longbits += $addlong;
                $latbits += !$addlong;
                $addlong = !$addlong;
            }


            //encode each as binary string
            $blat = $this->binEncode($lat, -90, 90, $latbits);
            $blong = $this->binEncode($long, -180, 180, $longbits);

            //merge lat and long together
            $binary = "";
            $uselong = 1;

            while (strlen($blat) + strlen($blong)) {
                if ($uselong) {
                    $binary = $binary . substr($blong, 0, 1);
                    $blong = substr($blong, 1);
                } else {
                    $binary = $binary.substr($blat, 0, 1);
                    $blat = substr($blat, 1);
                }

                $uselong = !$uselong;
            }

            //convert binary string to hash
            $hash="";

            for ($i = 0; $i < strlen($binary); $i+=5) {
                $n = bindec(substr($binary, $i, 5));
                $hash = $hash . $this->coding[$n];
            }


            return $hash;
        }