我想获取用户位置,但该方法总是返回 null 这是我的代码:
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 按钮,它也无法获得我当前的位置,但在此先感谢