0
我使用這些代碼來獲得位置爲什麼安卓不能得到位置的某個時候
但有時我不能在建築物內的位置,當時的WIFI連接,位置被啓用。
如何確保getLastKnownLocation在能夠獲取位置時返回位置?
LocationManager locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location == null)
{
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if(location==null)
{
Toast.makeText(getApplicationContext(),"no location", Toast.LENGTH_SHORT).show();
return;
}
使用fusedLocation它非常準確,快速 – Rahul
檢查這個演示http://javapapers.com/android/android-location-fused-provider/ –
@Rah良好的信息 –