Return to Snippet

Revision: 51493
at September 26, 2011 23:32 by efor18


Initial Code
public void cellID() {
			
			int cellID = GPRSInfo.getCellInfo().getCellId();
			int lac = GPRSInfo.getCellInfo().getLAC();
			
			try {
				String urlString2 = "http://www.google.com/glm/mmap";
				
				/* 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();

				if (code == 0) {
					latitude = (double) dataInputStream2.readInt() / 1000000D;
					longitude = (double) dataInputStream2.readInt() / 1000000D;

					userLocation = new Coordinates(latitude,longitude,0);
					
					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());
			}
		}

	 	/**
		 * Used to make the request to Google.
		 */
		private 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();
		}

Initial URL

                                

Initial Description

                                

Initial Title
Get Location by cellID in Blackberry 5.0

Initial Tags
google

Initial Language
Java