RVG
RVG

Reputation: 3576

How to get geolocation without GPS on Blackberry OS 5

I've got geolocation from GPS for OS 5 and above.

I need to get geolocation from the network. If GPS is disabled, I need to collect the geolocation information from the network for OS 5.

I've checked this BlackBerry document.

They give a solution for OS 6 and above.

Can we get geolocation without GPS for blackberry OS 5?

Upvotes: 4

Views: 515

Answers (2)

Nate
Nate

Reputation: 31045

Another option for you, in addition to @Signare's answer, is to use the Simple Location API, which is available for OS 5.0 and greater.

Download the source code from github and include it in your project.

Then, to acquire location fixes without using the GPS, try this:

 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

You can also use the SimpleLocationListener interface if you wish to have your code called back with location data at a specified interval.

In OS 6.0, this API adds the ability to specifically select the cell network as a location provider, or use the Wi-Fi network. In OS 5.0, you are limited to these three choices:

MODE_GEOLOCATION - Operates strictly in Geolocation mode.
MODE_GPS - Operates strictly in GPS (aka Standalone/Autonomous) mode.
MODE_OPTIMAL - Operates in both Geolocation and GPS mode based on availability.

But, using MODE_GEOLOCATION or MODE_OPTIMAL will allow you to get location fixes without using the GPS chip.

Upvotes: 1

Rince Thomas
Rince Thomas

Reputation: 4158

Try this -

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() method -

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

Upvotes: 2

Related Questions