我需要獲取某人在住宅內時的GPS位置。如何在房屋內獲取Android GPS位置
GPS在房子內不起作用,但我聽到有人解釋說,在Android中,您應該首先檢查GPS是否可用。如果不是,下一步就是根據附近的無線網絡對該人進行本地化。
我對此很新,我計劃開發一個簡單的鈦應用程序。我的問題是: 當gps不可用時,您可以基於無線網絡本地化某人嗎?我能得到建築物內人員的位置嗎?
我需要獲取某人在住宅內時的GPS位置。如何在房屋內獲取Android GPS位置
GPS在房子內不起作用,但我聽到有人解釋說,在Android中,您應該首先檢查GPS是否可用。如果不是,下一步就是根據附近的無線網絡對該人進行本地化。
我對此很新,我計劃開發一個簡單的鈦應用程序。我的問題是: 當gps不可用時,您可以基於無線網絡本地化某人嗎?我能得到建築物內人員的位置嗎?
似乎是一個良好的開端,我希望這個代碼可以幫助:
try {
gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {
}
try {
network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (Exception ex) {
}
// don't start listeners if no provider is enabled
if (!gps_enabled && !network_enabled) {
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("Attention!");
builder.setMessage("Sorry, location is not determined. Please enable location providers");
builder.create().show();
}
if (gps_enabled) {
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
}
if (network_enabled) {
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
}
從這裏:http://www.hrupin.com/2011/04/android-gps-using-how-to-get-current-location-example
一種選擇是天棚。這是他們的SDK的鏈接。它是android兼容的。這不會像GPS一樣準確,但它會讓你至少在大部分時間內在正確的建築物內。
,請撥打以下任何你想要得到CELLID定位CELLID功能。隨着GPS這不會是準確
public void cellID()
{
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
int cid = cellLocation.getCid();
int lac = cellLocation.getLac();
SimpleDateFormat sdfDateTime = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
datetimeCellID = sdfDateTime.format(new Date());
String cell_Id=String.valueOf(cid);
String gsm_Loc_Area_Code=String.valueOf(lac);
// Toast.makeText(getBaseContext(),"cellid="+cell_Id+"\nGsm Location Area Code:"+gsm_Loc_Area_Code,Toast.LENGTH_LONG).show();
if(RqsLocation(cid, lac))
{
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imeiCellID = tm.getDeviceId();
latitude_cellID=String.valueOf((float)myLatitude/1000000);
longitude_cellID=String.valueOf((float)myLongitude/1000000);
// Toast.makeText(getBaseContext(),"Lat:"+latitude_cellID+"Long:"+longitude_cellID,Toast.LENGTH_LONG).show();
}//if
else
{
Toast.makeText(getBaseContext(),"CellID : Can't find Location",Toast.LENGTH_LONG).show();
}//else
}
} // CELLID
private Boolean RqsLocation(int cid, int lac)
{
//Toast.makeText(getBaseContext(),"inReqloc",Toast.LENGTH_LONG).show();
Boolean result = false;
String urlmmap = "http://www.google.com/glm/mmap";
try {
URL url = new URL(urlmmap);
URLConnection conn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.connect();
OutputStream outputStream = httpConn.getOutputStream();
WriteData(outputStream, cid, lac);
InputStream inputStream = httpConn.getInputStream();
DataInputStream dataInputStream = new DataInputStream(inputStream);
dataInputStream.readShort();
dataInputStream.readByte();
int code = dataInputStream.readInt();
if (code == 0)
{
myLatitude = dataInputStream.readInt();
myLongitude = dataInputStream.readInt();
result = true;
}
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
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();
}
如何準確這是否必要呢?你只需要弄清楚某人在哪裏,或者你需要知道某個人的某個腳的位置? – Brad 2012-03-29 19:38:57