I am Stuck with a issue to get langitude and latitude, when i am trying
GPRS methos it take more time to give the result(in many cases may be in
hours), and when i try to calculate it by Cellid and lac, it work fine but
not in all cases in some case i got value of cell id and LAC which are
invalid... please help me to solve the situation and what will be the
better approach to solve it, code that i am using by now is
public String getLocation(){
try{
/*
* Code Block to get mcc mnc cellId lac.
*/
TelephonyManager telephonyManager =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation)
telephonyManager.getCellLocation();
String networkOperator = telephonyManager.getNetworkOperator();
String mcc = networkOperator.substring(0, 3);
String mnc = networkOperator.substring(3);
// cellId
int cellID = cellLocation.getCid();//12243;//
System.out.println("cellId = "+cellID);
int lac = cellLocation.getLac();//240;//
/*
* Code Block to get to Hit Google Link by posting cellid and lac
* to get Latitude and Langitude.
*/
String urlString = "http://www.google.com/glm/mmap";
//---open a connection to Google Maps API---
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.connect();
//---write some custom data to Google Maps API---
OutputStream outputStream = httpConn.getOutputStream();
WriteData(outputStream, cellID, lac);
//---get the response---
InputStream inputStream = httpConn.getInputStream();
DataInputStream dataInputStream = new DataInputStream(inputStream);
//---interpret the response obtained---
dataInputStream.readShort();
dataInputStream.readByte();
int code = dataInputStream.readInt();
String uriString = "";
if(code == 0){
//String s = new String(dataInputStream);
double lat = (double) dataInputStream.readInt() / 1000000D;
double lng = (double) dataInputStream.readInt() / 1000000D;
//---display Google Maps---
uriString = "latitude : " + lat
+ ", longitude : " + lng;
return uriString;
}else{
return "Error in finding location "+" Code = "+code+" lac =
"+lac+" cellId = "+cellID+" mcc = "+mcc+" mnc = "+mnc;
}
}catch (Exception e) {
// TODO: handle exception
return "Exception in finding location "+e+" && "+e.getMessage();
}
}
private void WriteData(OutputStream out, int cid, 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(cid);
dataOutputStream.writeInt(lac);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(0);
dataOutputStream.flush();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en