且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用手机信号塔位置的Andr​​oid

更新时间:2023-02-27 08:34:34

  TelephonyManager telephonyManager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  GsmCellLocation cellLocation =(GsmCellLocation)telephonyManager.getCellLocation();  INT CELLID = cellLocation.getCid();
  INT celllac = cellLocation.getLac(); Log.d(CellLocation,cellLocation.toString());
 Log.d(GSM CELL ID,将String.valueOf(CELLID));
 Log.d(GSM位置code,将String.valueOf(celllac));

请确保您有这些权限在您的清单中。

 <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>

如果你真的想实​​际位置使用HttpClient的或有点查询 http://www.google。 COM / GLM / MMAP 与CELLID和LAC。例如在此列出。的http://www.anddev.org/poor_mans_gps_-celltowerid-_location_area_$c$c_-lookup-t257.html

How can I retrieve my location using cell towers? when GPS and Wifi is off.

I know i can retrevive cellID of towers, but how can i map it to get Latitude and Longitude of my current location?

I don't care if it isn't accurate location.

I have found some snippets but seems using wifi.

  TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();

  int cellid= cellLocation.getCid();
  int celllac = cellLocation.getLac();

 Log.d("CellLocation", cellLocation.toString());
 Log.d("GSM CELL ID",  String.valueOf(cellid));
 Log.d("GSM Location Code", String.valueOf(celllac));

Make sure that you have those permissions in your manifest.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

If you really want the real position use a httpclient or somewhat to query http://www.google.com/glm/mmap with your cellid and lac. Example is listed here. http://www.anddev.org/poor_mans_gps_-celltowerid-_location_area_code_-lookup-t257.html