Get Location by cellID in Blackberry 5.0


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public void cellID() {
  2.  
  3. int cellID = GPRSInfo.getCellInfo().getCellId();
  4. int lac = GPRSInfo.getCellInfo().getLAC();
  5.  
  6. try {
  7. String urlString2 = "http://www.google.com/glm/mmap";
  8.  
  9. /* Open a connection to Google Maps API */
  10. ConnectionFactory connFact = new ConnectionFactory();
  11. ConnectionDescriptor connDesc;
  12. connDesc = connFact.getConnection(urlString2);
  13.  
  14. HttpConnection httpConn2;
  15. httpConn2 = (HttpConnection)connDesc.getConnection();
  16. httpConn2.setRequestMethod("POST");
  17.  
  18. /* Write some custom data to Google Maps API */
  19. OutputStream outputStream2 = httpConn2.openOutputStream();//getOutputStream();
  20. WriteDataGoogleMaps(outputStream2, cellID, lac);
  21.  
  22. /* Get the response */
  23. InputStream inputStream2 = httpConn2.openInputStream();//getInputStream();
  24. DataInputStream dataInputStream2 = new DataInputStream(inputStream2);
  25.  
  26. /* Interpret the response obtained */
  27. dataInputStream2.readShort();
  28. dataInputStream2.readByte();
  29.  
  30. int code = dataInputStream2.readInt();
  31.  
  32. if (code == 0) {
  33. latitude = (double) dataInputStream2.readInt() / 1000000D;
  34. longitude = (double) dataInputStream2.readInt() / 1000000D;
  35.  
  36. userLocation = new Coordinates(latitude,longitude,0);
  37.  
  38. dataInputStream2.readInt();
  39. dataInputStream2.readInt();
  40. dataInputStream2.readUTF();
  41.  
  42. } else {
  43. System.out.println("Error obtaining Cell Id ");
  44. }
  45. outputStream2.close();
  46. inputStream2.close();
  47. } catch (Exception e) {
  48. System.out.println("Error: " + e.getMessage());
  49. }
  50. }
  51.  
  52. /**
  53. * Used to make the request to Google.
  54. */
  55. private void WriteDataGoogleMaps(OutputStream out, int cellID, int lac)
  56. throws IOException {
  57. DataOutputStream dataOutputStream = new DataOutputStream(out);
  58. dataOutputStream.writeShort(21);
  59. dataOutputStream.writeLong(0);
  60. dataOutputStream.writeUTF("en");
  61. dataOutputStream.writeUTF("Android");
  62. dataOutputStream.writeUTF("1.0");
  63. dataOutputStream.writeUTF("Web");
  64. dataOutputStream.writeByte(27);
  65. dataOutputStream.writeInt(0);
  66. dataOutputStream.writeInt(0);
  67. dataOutputStream.writeInt(3);
  68. dataOutputStream.writeUTF("");
  69.  
  70. dataOutputStream.writeInt(cellID);
  71. dataOutputStream.writeInt(lac);
  72.  
  73. dataOutputStream.writeInt(0);
  74. dataOutputStream.writeInt(0);
  75. dataOutputStream.writeInt(0);
  76. dataOutputStream.writeInt(0);
  77. dataOutputStream.flush();
  78. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.