我需要获取某人在住宅内时的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