我用Android手机在室外定位,回到室内,没有GPS信号。这里调用getLastKnownLocation()返回的定位结果是上次的定位结果,事实是(室内)没有GPS信号。如何刷新GPS状态?
发布于 2012-12-11 11:52:38
如果你在室内测试,试着同时使用网络和gps卫星(注意:来自网络的位置信息有时不是100%准确的)
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);并等待一段时间,以便从gps接收器获得gps定位。正常情况下,如果信号强度较小,则需要2到3分钟,可能需要很长时间。
如果您遇到任何问题,请把您的代码,我们将检查
发布于 2012-12-11 12:05:33
正如Abhijit所说,当你在窗外或窗口附近时,你可以使用这些代码行来获取GPS坐标。
然而,当你在房间或地下室里,你仍然想要找到GPS坐标,你可以尝试这种替代方法,
当你在地下室或房间里时,你仍然可以获得网络覆盖(网络信号)。因此,您可以在这里使用TelePhony应用程序接口来获取全球定位系统坐标。
String mcc; //Mobile Country Code
String mnc; //mobile network code
String cellid; //Cell ID
String lac; //Location Area Code
//retrieve a reference to an instance of TelephonyManager
TelephonyManager telephonyManager = (TelephonyManager) myContext.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();
String networkOperator = telephonyManager.getNetworkOperator();
cellid = String.valueOf( cellLocation.getCid() );
lac = String.valueOf( cellLocation.getLac() );
mcc = networkOperator.substring( 0, 3 );
mnc = networkOperator.substring( 3 );现在将这个cellid、lac、mcc和mnc值传递给opencellid.org,您将得到纬度和经度值。
发布于 2012-12-11 12:48:58
您可以根据需要每隔5分钟启动一次服务。您可以使用pending Intent
long UPDATE_INTERVAL=300000;
Intent myIntent=new Intent(Main.this,YourGPSLOcationClass.class);
PendingIntent pendingIntent=PendingIntent.getService(Main.this,0,myIntent,0);
AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
Calendar cal=Calendar.getInstance();
cal.add(Calendar.MINUTE,0);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),UPDATE_INTERVAL,pendingIntent);https://stackoverflow.com/questions/13813259
复制相似问题