2013-06-19 2 views
4

OS 5 이상의 GPS에서 geolocation을 얻었습니다.GPS가없는 Geolocation을 Blackberry OS 5에 얻는 방법

네트워크에서 geolocation을 가져와야합니다. GPS가 비활성화 된 경우 네트워크에서 OS 5에 대한 위치 정보를 수집해야합니다.

this BlackBerry document을 확인했습니다.

OS 6 이상의 솔루션을 제공합니다.

GPS가없는 Geolocation을 블랙 베리 OS 5에 사용할 수 있습니까?

답변

2

이 시도 -

try { 

    int cellID = GPRSInfo.getCellInfo().getCellId(); 
    int lac = GPRSInfo.getCellInfo().getLAC(); 

    String urlString2 = "http://www.google.com/glm/mmap"; 
    if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) 
      && RadioInfo 
        .areWAFsSupported(RadioInfo.WAF_WLAN)) { 
     urlString2 += ";interface=wifi;ConnectionTimeout=60000"; 
    }else if (TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_BIS_B) && TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_BIS_B)) { 
     System.out.println("BIS CONNECTION-------------------"); 
     // Holder.connectionInterface=";deviceside=false;ConnectionType=mds-public"; 
     urlString2 += ";deviceside=false;ConnectionType=mds-public;ConnectionTimeout=60000"; 
    } 


    // 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(); 
} 
+0

안녕하세요 .. WriteDataGoogleMaps() 메소드에서 우리가하는 일은 무엇입니까? – RVG

+0

@Ganesh 나는 대답을 편집했다. 지금 그것을 확인하십시오. – Signare

+0

안녕하세요 signare .. 그 .. 감사합니다 .. – RVG

1

뿐만 아니라 당신을위한 또 다른 옵션, @Signare's answer에를, OS 5.0에 사용할 수있는 Simple Location API 사용하는 것입니다 이상.

Download the source code from github 프로젝트에 포함하십시오.

그런 다음, GPS를 사용하지 않고 위치 수정을 획득,이 시도 : 당신은 당신의 코드가 지정에 위치 데이터를 다시 불렀다하고자하는 경우

try { 
    simpleProvider = new SimpleLocationProvider(SimpleLocationProvider.MODE_GEOLOCATION); 
} catch(LocationException le){ 
    // thrown if the selected mode (in this case MODE_GEOLOCATION) is not available. 
} 
BlackBerryLocation location = simpleProvider.getLocation(120); // 120 seconds timeout 

당신은 또한 SimpleLocationListener 인터페이스를 사용할 수 있습니다 간격은입니다.

OS 6.0에서이 API는 셀 네트워크를 위치 제공 업체로 선택하거나 Wi-Fi 네트워크를 사용할 수있는 기능을 추가합니다. OS 5.0에서는 이러한 세 가지 선택에 제한됩니다

MODE_GEOLOCATION이 - 지리적 위치 모드에서 엄격하게 작동합니다.
MODE_GPS - GPS (독립 실행 형/자율) 모드에서만 작동합니다.
MODE_OPTIMAL - 이용 가능 여부에 따라 Geolocation 및 GPS 모드에서 모두 작동합니다. 당신은 GPS 칩을 사용하지 않고 위치 수정을 얻을 수 MODE_GEOLOCATION 또는 MODE_OPTIMAL를 사용하여

하지만.

+0

안녕하세요. 내 장치 9550에 대구 파일을로드했습니다. 'GEOLOATION'을 선택하면 예외가 발생합니다. javax.microedition.locaion.LocaionEception :이 장치에서는 현재 MODE_GEOLOCATION을 사용할 수 없습니다. – RVG

+0

@ 가넷 (Ganesh), 시도해 보았을 때 모바일 인터넷 서비스 (네트워크 사용 가능)를 사용 했습니까? 단지이 모드는 GSM이나 CDMA 셀룰러 네트워크를 사용하는'GPSInfo.GPS_MODE_CELLSITE'를 사용합니다. 테스트 장치 ** **에만 Wi-Fi 연결이 있지만 유효한 이동 통신사 네트워크가 아닌 경우에는 작동하지 않습니다. 다른 답변에 대한 귀하의 의견을 보면 Wi-Fi가없는 위치를 찾는 방법을 찾는 것처럼 보입니다. 특히 OS 5.0에서 위치 서비스를 사용하면 기술 조합이 필요하기 때문에 Signare 이외에도이 두 번째 대답을 추가했습니다. – Nate

+0

예. 내 휴대폰에 인터넷이 있습니다. 3g sim을 삽입했고 wifi도 사용할 수 있습니다. – RVG

관련 문제