doxn43207 2013-07-22 05:19
浏览 30

将CID转换为LAT时,PHP会产生不同的结果

I have scripts that will converting CID to LAT and LAC to LONG. In my localhost everything well but in the production server (using the same script) give me different result.

Result in localhost: CID = 55073 => LAT = -6.254678 (TRUE RESULT)

Result in production server CID = 55073 => LAT = 4288.712618 (INCORRECT RESULT)

Here's my script

if(isset($lac) && isset ($cid)) 
    {

        $data = "\x00\x0e" .
        "\x00\x00\x00\x00\x00\x00\x00\x00" .
        "\x00\x00" .
        "\x00\x00" .
        "\x00\x00" .
        "\x1b" .
        "\x00\x00\x00\x00" .
        "\x00\x00\x00\x00" .
        "\x00\x00\x00\x00" .
        "\x00\x00" .
        "\x00\x00\x00\x00" .
        "\x00\x00\x00\x00" .
        "\x00\x00\x00\x00" .
        "\x00\x00\x00\x00" .
        "\xff\xff\xff\xff" .
        "\x00\x00\x00\x00";

        $is_umts_cell = ($cid > 65535);
        if ($is_umts_cell) // GSM: 4 hex digits, UTMS: 6 hex digits
            $data[0x1c] = 5;
        else
            $data[0x1c] = 3;

        $hexlac = substr("00000000" . dechex($lac), -8);
        $hexcid = substr("00000000" . dechex($cid), -8);

        $data[0x1f] = pack("H*", substr($hexcid, 0, 2));
        $data[0x20] = pack("H*", substr($hexcid, 2, 2));
        $data[0x21] = pack("H*", substr($hexcid, 4, 2));
        $data[0x22] = pack("H*", substr($hexcid, 6, 2));

        $data[0x23] = pack("H*", substr($hexlac, 0, 2));
        $data[0x24] = pack("H*", substr($hexlac, 2, 2));
        $data[0x25] = pack("H*", substr($hexlac, 4, 2));
        $data[0x26] = pack("H*", substr($hexlac, 6, 2));

        /* I used file_get_contents() at my laptop webserver, but it seems like the PHP version
         * at my hosting company is old and it is not supporting that.
         * For the hosting company, here we're using cURL.
         */
        $use_curl = true;
        if ($use_curl) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://www.google.com/glm/mmap");
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, Array (
                "Content-type: application/binary"
            ));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_POST, 1);
            $response = curl_exec($ch);
            if (curl_errno($ch))
                return -1;

            $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
            $str = substr($response, $header_size);

            curl_close($ch);
        } else {
            $context = array (
                'http' => array (
                    'method' => 'POST',
                    'header' => "Content-type: application/binary
" . "Content-Length: " . strlen($data
                ) . "
",
                'content' => $data
            ));
            $xcontext = stream_context_create($context);
            $str = file_get_contents("http://www.google.com/glm/mmap", FALSE, $xcontext);
            echo 'use post'; exit;
        }

        $opcode1 = ((ord($str[0]) << 8)) | ord($str[1]);
        $opcode2 = ord($str[2]);

        if (($opcode1 != 0x0e) || ($opcode2 != 0x1b))
            return -2;

        $retcode = ((ord($str[3]) << 24) | (ord($str[4]) << 16) | (ord($str[5]) << 8) | (ord($str[6])));
        if ($retcode != 0)
            return -2;

        $lat = ((ord($str[7]) << 24) | (ord($str[8]) << 16) | (ord($str[9]) << 8) | (ord($str[10]))) / 1000000;
        $lon = ((ord($str[11]) << 24) | (ord($str[12]) << 16) | (ord($str[13]) << 8) | (ord($str[14]))) / 1000000;

        // exit script if cannot geocode cell e.g. not on google's database
        if ($lat == 0 and $lon == 0)
            return -3;

        $data = array(
           'cellid' => $cid,
           'lac' => $lac,
           'lat' => $lat,
           'lon' => $lon,
        );

        if($retr)
        {
            return array (
                "lat" => $lat,
                "lng" => $lon
            );
        }else{
            header('Cache-Control: no-cache, must-revalidate');
            header('Content-type: application/json');
            echo json_encode(array(
                                'lat' => $lat,
                                'lng' => $lon
                            ));
        }
    }   
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统