How to get geolocation without GPS on Blackberry OS 5

I have GPS geolocation for OS 5 and above.

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

I checked this BlackBerry doc .

They provide a solution for OS 6 and above.

Can we get GPS-free geolocation for Blackberry OS 5?

+4
source share
2 answers

Try it -

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

Another option for you, besides @Signare answer , is to use the Simple Location API , which is available for OS 5.0 and higher.

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

Then, to get location corrections without using GPS, try the following:

  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 want your code to return with location data at a given interval.

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

MODE_GEOLOCATION . It works strictly in geolocation mode.
MODE_GPS - Works strictly in GPS mode (it is autonomous / autonomous).
MODE_OPTIMAL . It works both in geolocation mode and in GPS mode based on availability.

But using MODE_GEOLOCATION or MODE_OPTIMAL , you can get location corrections without using a GPS chip.

+1
source

Source: https://habr.com/ru/post/1486979/


All Articles