0

GPSを使用せずにBlackberryデバイスの位置を取得したい。そのため、結果としてOpencellidを使用しています。しかし、それは私に間違った場所の結果を与えています。正確な手順と私が間違っている可能性があることを誰かが明確にできますか?

私のコード:

public final static String getQueryString(){
    cellID = Integer.toString(GPRSInfo.getCellInfo().getCellId());
    // Retrieves the Location Area Code.
    lac = Integer.toString(GPRSInfo.getCellInfo().getLAC());
    // Retrieves the mobile country code.
    mcc = Integer.toHexString(RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex()));
    // Retrieves the Location network Code.
    mnc = Integer.toHexString(RadioInfo.getMNC(RadioInfo.getCurrentNetworkIndex()));     
    queryStr="http://www.opencellid.org/cell/get?
    key="+myapikey+"&mcc="+mcc+"&mnc="+mnc+"&cellid="+cellID+"&lac="+lac+"&fmt=txt";
    return queryStr;
}

public void httpGetRequest(){
    HttpConnection conn = null;
    InputStream in = null; StringBuffer buff = new StringBuffer(); String result = "";
    try {
        conn=(HttpConnection) Connector.open(getQueryString()+getString(),Connector.READ);
        conn.setRequestMethod(HttpConnection.GET); conn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
        conn.setRequestProperty("Content-Type", "plain/text");
        in = conn.openInputStream();

        int car;
        while( (car=in.read())!= -1){
            buff.append((char)car);
        }
        in.close();
        conn.close();
        result=buff.toString();

        //get latitude and longitude
        if(result.startsWith("err")){
            System.out.println("Cell not found!");
        }else{
            int pos=result.indexOf(',');
            String lat=result.substring(0,pos);
            int pos2=result.indexOf(',',pos+1);
            String lon=result.substring(pos+1,pos2);
            System.out.println(lat+" "+lon);
            getLocationFromGoogleMaps(lat,lon);
        }
    } catch (Exception ex) {
        System.out.println("====Exception: "+ex.getMessage());
    } finally {
        try {
            if (in != null) {
                in.close();
            }
            conn.close();
        } catch (IOException e) {
            System.out.println("====Exception: "+e.getMessage());
        }
    }
} 
4

1 に答える 1

0

これを試して -

            try {

                int cellID = GPRSInfo.getCellInfo().getCellId();
                int lac = GPRSInfo.getCellInfo().getLAC();
                String urlString2 = "http://www.google.com/glm/mmap";
                // Open a connection to Google Maps API 
                ConnectionFactory connFact = new ConnectionFactory();                   ConnectionDescriptor connDesc;
                connDesc = connFact.getConnection(urlString2);

                HttpConnection httpConn2;
                httpConn2 = (HttpConnection)connDesc.getConnection();
                httpConn2.setRequestMethod("POST");

                // Write some custom data to Google Maps API 
                OutputStream outputStream2 = httpConn2.openOutputStream();//getOutputStream();
                WriteDataGoogleMaps(outputStream2, cellID, lac);

                // Get the response  
                InputStream inputStream2 = httpConn2.openInputStream();//getInputStream();
                DataInputStream dataInputStream2 = new DataInputStream(inputStream2);

                // Interpret the response obtained 
                dataInputStream2.readShort();
                dataInputStream2.readByte();

                int code = dataInputStream2.readInt();
                //Dialog.alert(code+"");

                if (code == 0) {
                    latitude= dataInputStream2.readInt() / 1000000D;
                    longitude=dataInputStream2.readInt() / 1000000D;

                    //Dialog.alert(latitude+"-----"+longitude);  

                    dataInputStream2.readInt();
                    dataInputStream2.readInt();
                    dataInputStream2.readUTF();

                } else {
                    System.out.println("Error obtaining Cell Id ");
                }
                outputStream2.close();
                inputStream2.close();
            } catch (Exception e) {
                System.out.println("Error: " + e.getMessage());
            }

WriteDataGoogleMaps関数を以下に示します-

 private static void WriteDataGoogleMaps(OutputStream out, int cellID, int lac)
throws IOException {
    DataOutputStream dataOutputStream = new DataOutputStream(out);
    dataOutputStream.writeShort(21);
    dataOutputStream.writeLong(0);
    dataOutputStream.writeUTF("en");
    dataOutputStream.writeUTF("Android");
    dataOutputStream.writeUTF("1.0");
    dataOutputStream.writeUTF("Web");
    dataOutputStream.writeByte(27);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(3);
    dataOutputStream.writeUTF("");
    dataOutputStream.writeInt(cellID);
    dataOutputStream.writeInt(lac);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.writeInt(0);
    dataOutputStream.flush();
}
于 2012-10-30T11:47:55.547 に答える