1
您好,我是android開發新手。我想獲得當前位置,但我需要等待聽衆開始工作。問題是我沒有改變位置,所以聽衆不能工作(?)!如何在位置不變的情況下獲取當前位置
這裏是我的代碼
我的聽衆樣本:
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
textView.append(location.getLongitude() + "\n" + location.getLatitude() + "\n");
// just monitoring
lat = location.getLatitude();
lng = location.getLongitude();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
};
,我獲得此
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 300, 0, locationListener);
更新所以,如果我沒有記錯的GPS將採取新的位置基於時間(300毫秒)或基於距離是0,所以它會工作?我應該等一段時間開始服用嗎?多久?超過2分鐘?
我得到的Wi-Fi打開,當然GPS,這是我的清單
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Details" />
<activity android:name=".LoginMenu" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity android:name=".Road" />
<activity android:name=".LoopActivity" />
<activity android:name=".Pedestrians"></activity>
</application>
的問候非常感謝
嘗試將權限從「ACCESS_COARSE_LOCATION」更改爲「ACCESS_FINE_LOCATION」。 – iTurki
我得到了他們倆。你的意思是刪除一個? –