我想獲得用戶的位置,但該方法總是返回空值,這是我的代碼:獲取最後已知的位置總是返回NULL SDK 23
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
SystemProvider = locationManager.getBestProvider(new Criteria(),true);
UserLocation = locationManager.getLastKnownLocation(SystemProvider);
if(UserLocation==null)
{
Log.i("Exc2","No Location");
mMap.addMarker(new MarkerOptions().position(new LatLng(0,0)).title("No Location"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(0,0),10));
}
else {
double one = UserLocation.getLatitude();
double two = UserLocation.getLongitude();
mMap.addMarker(new MarkerOptions().position(new LatLng(one, two)).title("HMS"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(one, two), 10));
}
我已經嘗試過很多辦法,但是當我打開谷歌什麼都沒有發生,甚至地圖上的仿真器和壓在GPS按鈕,它是無法得到我的當前位置 由於事先
查看一步一步的指導答案:http://stackoverflow.com/a/38397092/5955362 –