网上找了半天了。。 真是个个都不能用啊。。
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 , 0 , locationListener); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
location 等于null还有
TelephonyManager tm;
tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
int cid = gcl.getCid();这个也为null
好像是2.2api 移除了这些。。
请问大家是怎么实现定位的? 直接贴代码哈!!
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 , 0 , locationListener); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
location 等于null还有
TelephonyManager tm;
tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
int cid = gcl.getCid();这个也为null
好像是2.2api 移除了这些。。
请问大家是怎么实现定位的? 直接贴代码哈!!
如果你先用个什么其他的定位软件,让手机处于定位状态,然后再运行你的程序,就应该能取到位置信息了。不过,显然事情不应该是这样的。locationListener 是一个callback,也就是说,在定位的情况下,在位置变化满足你设定的要求的时候(时间和距离),这个callback函数会被系统调用。
你把当位置发生变化的时候,需要做的事情,放在这个callback函数里。
简单一点,你可以在这个callback里放入logcat来打印位置信息。locationListener 的函数参数里面就有location信息,可以直接用。
当然,如果你愿意,你也可以再用getLastKnownLocation去取一次。
http://www.cnblogs.com/patui/archive/2011/09/10/2173434.html大量代码资源可参考:
http://download.csdn.net/tag/ANDROID%E5%9F%BA%E7%AB%99%E5%AE%9A%E4%BD%8D
第一个 TelephonyManager mTelNet = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String operator=mTelNet.getNetworkOperator();
operator 就为null了 后面的代码 全部看都不用看了。第二个的话,我下载了很多。。在2.2 都不行额。。