在Blackberry 5.0中通过cellID获取位置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Blackberry 5.0中通过cellID获取位置相关的知识,希望对你有一定的参考价值。

  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. }

以上是关于在Blackberry 5.0中通过cellID获取位置的主要内容,如果未能解决你的问题,请参考以下文章

在黑莓中通过 GPS 获取坐标

C ++:我在一种方法中获得了一个迭代器,如何在另一种方法中通过迭代器修改原始列表?

如何使用来自 blackberry 5.0 的 HTTP POST 上传音频文件?

如何在 BlackBerry 5.0 及更高版本的 J2ME 代码中使用 wifi 调用 web 服务? [复制]

如何在 BlackBerry 5.0 及更高版本的 J2ME 代码中使用 wifi 调用 HTTP URL?

如何在Objective C中通过UIView获取UIAlertController?